List of utility methods to do Bitmap Color Change
int[] | getGrayscaleHistogram(Bitmap bm) get Grayscale Histogram int[] histogram = new int[256]; int ptr = 0; while (ptr < histogram.length) histogram[ptr++] = 0; int hlen = bm.getWidth(), vlen = bm.getHeight(); int pixel; for (int y = 0; y < vlen; y++) { for (int x = 0; x < hlen; x++) { ... |
Bitmap | increaseGreen(Bitmap src, int value) Increase green. int width = src.getWidth(); int height = src.getHeight(); final float factor = 1.1f; Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig()); int[] pix = new int[width * height]; src.getPixels(pix, 0, width, 0, 0, width, height); int A, R, G, B; int i = 0; ... |
boolean | initAlphaChannel( BitmapFactory.Options bitmapOptions) set bitmap options preferred config if (!TextUtils.isEmpty(bitmapOptions.outMimeType)) { if (mayNotHasAlphaChannel(bitmapOptions)) { bitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565; bitmapOptions.inDither = false; } else { bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; return true; ... |
boolean | initBitmapFactoryOptions( BitmapFactory.Options bitmapOptions, int maxWidth, int maxHeight) init Bitmap Factory Options if (bitmapOptions.inJustDecodeBounds && bitmapOptions.outHeight > 0 && bitmapOptions.outWidth > 0) { if (bitmapOptions.outWidth > (maxWidth << 1) || bitmapOptions.outHeight > (maxHeight << 1)) { bitmapOptions.inSampleSize = Math.max( bitmapOptions.outWidth / maxWidth, bitmapOptions.outHeight / maxHeight); bitmapOptions.inJustDecodeBounds = false; return true; return false; |
Bitmap | makeSaturated(Bitmap source, int level) Make colors of bitmap saturated. int width = source.getWidth(); int height = source.getHeight(); int[] pixels = new int[width * height]; float[] HSV = new float[3]; source.getPixels(pixels, 0, width, 0, 0, width, height); int index = 0; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { ... |
Bitmap | makeVivid(Bitmap src, int type, float percent) Make colors in bitmap vivid. int width = src.getWidth(); int height = src.getHeight(); Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig()); int A, R, G, B; int pixel; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { pixel = src.getPixel(x, y); ... |
Bitmap | setAlpha(Bitmap sourceImg, int number) set Alpha int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()]; sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg.getWidth(), sourceImg.getHeight()); number = number * 255 / 100; for (int i = 0; i < argb.length; i++) { argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF); sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), ... |
Bitmap | setAlpha(Bitmap sourceImg, int number) set Alpha int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()]; sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg.getWidth(), sourceImg.getHeight()); number = number * 255 / 100; for (int i = 0; i < argb.length; i++) { argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF); sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), ... |
Bitmap | tiltShift(Bitmap sentBitmap, int radius, int x, int y) Tilt shift effect on bitmap. Bitmap bmp = sentBitmap.copy(sentBitmap.getConfig(), true); int w = sentBitmap.getWidth(); int h = sentBitmap.getHeight(); int[] pix = new int[w * h]; bmp.getPixels(pix, 0, w, 0, 0, w, h); int radiusSquared = 110 * 110; for (int r = radius; r > 1; r /= 2) { for (int i = r; i < h - r; i++) { ... |
Bitmap | changeBitmapColor(Bitmap bmp, int color) change Bitmap Color Bitmap result = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig()); Canvas c = new Canvas(result); Paint paint = new Paint(); ColorFilter filter = new LightingColorFilter(color, 1); paint.setColorFilter(filter); c.drawBitmap(bmp, 0, 0, paint); return result; ... |