Mobile Application Developer

Home » , » How to invert bitmap color

How to invert bitmap color

Written By Mitul Nakum on Thursday, November 17, 2011 | 10:23 AM

public static Bitmap invert(Bitmap src) {                 Bitmap output = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());                 int A, R, G, B;                 int pixelColor;                 int height = src.getHeight();                 int width = src.getWidth();             for (int y = 0; y < height; y++) {                 for (int x = 0; x < width; x++) {                     pixelColor = src.getPixel(x, y);                     A = Color.alpha(pixelColor);                                         R = 255 - Color.red(pixelColor);                     G = 255 - Color.green(pixelColor);                     B = 255 - Color.blue(pixelColor);                                         output.setPixel(x, y, Color.argb(A, R, G, B));                 }             }             return output;         }  

About Mitul Nakum

15+ years of experience in mobile application development which includes Symbian, J2ME, Android and iOS development

0 comments :

Post a Comment