DavidNorgren

Untitled

Apr 24th, 2014
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1.         int imgWidth = img.getWidth();
  2.         int imgHeight = img.getHeight();
  3.         int[][] colors = new int[imgWidth][imgHeight];
  4.  
  5.         for (int x = 0; x < imgWidth; x++) {
  6.             for (int y = 0; y < imgHeight; y++) {
  7.                 colors[x][y] = img.getPixel(x,y);
  8.             }
  9.         }
  10.  
  11.         Bitmap editBitmap = Bitmap.createBitmap(imgWidth, imgHeight, Bitmap.Config.ARGB_8888);
  12.  
  13.         for (int x = 0; x < imgWidth; x++) {
  14.             for (int y = 0; y < imgHeight; y++) {
  15.                 int averageRed = 0, averageGreen = 0, averageBlue = 0;
  16.                 int samples = 0;
  17.  
  18.                 for (int a = x - amount; a <= x + amount; a++) {
  19.                     for (int b = y - amount; b <= y + amount; b++) {
  20.                         if (a < 0 || a >= imgWidth || b < 0 || b >= imgHeight) continue;
  21.                         int currentColor = colors[a][b];
  22.                         averageRed += Color.red(currentColor);
  23.                         averageGreen += Color.green(currentColor);
  24.                         averageBlue += Color.blue(currentColor);
  25.                         samples++;
  26.                     }
  27.                 }
  28.  
  29.                 averageRed /= samples;
  30.                 averageGreen /= samples;
  31.                 averageBlue /= samples;
  32.  
  33.                 editBitmap.setPixel(x, y, Color.argb(255, averageRed, averageBlue, averageGreen));
  34.             }
  35.         }
  36.  
  37.         return editBitmap;
Advertisement
Add Comment
Please, Sign In to add comment