Advertisement
Javi

boost de colores

Jul 25th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1.     enum ColorComponent {RED, GREEN, BLUE};
  2.    
  3.     private Bitmap boostImpl(Bitmap bitmap, ColorComponent comp, float percent) {
  4.         int width = bitmap.getWidth();
  5.         int height = bitmap.getHeight();
  6.         Bitmap bitmapDest = Bitmap.createBitmap(width, height, bitmap.getConfig());
  7.  
  8.         int alpha, red, green, blue;
  9.         int pixel;
  10.  
  11.         for (int i = 0; i < width; ++i) {
  12.             for (int j = 0; j < height; ++j) {
  13.                 pixel = bitmap.getPixel(i, j);
  14.                 alpha = Color.alpha(pixel);
  15.                 red = Color.red(pixel);
  16.                 green = Color.green(pixel);
  17.                 blue = Color.blue(pixel);
  18.                 if (comp == ColorComponent.RED) {
  19.                     red = (int) (red * (1 + percent));
  20.                     if (red > 255) {
  21.                         red = 255;
  22.                     }
  23.                 } else if (comp == ColorComponent.GREEN) {
  24.                     green = (int) (green * (1 + percent));
  25.                     if (green > 255) {
  26.                         green = 255;
  27.                     }
  28.                 } else if (comp == ColorComponent.BLUE) {
  29.                     blue = (int) (blue * (1 + percent));
  30.                     if (blue > 255) {
  31.                         blue = 255;
  32.                     }
  33.                 }
  34.                 bitmapDest.setPixel(i, j, Color.argb(alpha, red, green, blue));
  35.             }
  36.         }
  37.         return bitmapDest;
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement