Image Processing – Decreasing Color Depth
Decreasing color depth involves converting to standard values.
For example: if I want to offset 32, then each image color channel will apply the range: 0, 31, 63 …
From the original image:
Some bit offset taken for this image:
Here the implementation:
public static Bitmap decreaseColorDepth(Bitmap src, int bitOffset) { // get image size int width = src.getWidth(); int height = src.getHeight(); // create output bitmap Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig()); // color information int A, R, G, B; int pixel; // scan through all pixels for(int x = 0; x < width; ++x) { for(int y = 0; y < height; ++y) { // get pixel color pixel = src.getPixel(x, y); A = Color.alpha(pixel); R = Color.red(pixel); G = Color.green(pixel); B = Color.blue(pixel); // round-off color offset R = ((R + (bitOffset / 2)) - ((R + (bitOffset / 2)) % bitOffset) - 1); if(R < 0) { R = 0; } G = ((G + (bitOffset / 2)) - ((G + (bitOffset / 2)) % bitOffset) - 1); if(G < 0) { G = 0; } B = ((B + (bitOffset / 2)) - ((B + (bitOffset / 2)) % bitOffset) - 1); if(B < 0) { B = 0; } // set pixel color to output bitmap bmOut.setPixel(x, y, Color.argb(A, R, G, B)); } } // return final image return bmOut; }
Hope you like it!
Cheers,
Pete Houston
Categories: Tutorials
color, decreasing, depth, image, processing
The post office is always out of tge way for me. Bleh! I need to check it too, ah!
can you help
I want to get a 4 – bit image
I changed the parameter bitOffset to a larger but did not achieve a positive result
ThanX
Great work…