Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int imgWidth = img.getWidth();
- int imgHeight = img.getHeight();
- int[][] colors = new int[imgWidth][imgHeight];
- for (int x = 0; x < imgWidth; x++) {
- for (int y = 0; y < imgHeight; y++) {
- colors[x][y] = img.getPixel(x,y);
- }
- }
- Bitmap editBitmap = Bitmap.createBitmap(imgWidth, imgHeight, Bitmap.Config.ARGB_8888);
- for (int x = 0; x < imgWidth; x++) {
- for (int y = 0; y < imgHeight; y++) {
- int averageRed = 0, averageGreen = 0, averageBlue = 0;
- int samples = 0;
- for (int a = x - amount; a <= x + amount; a++) {
- for (int b = y - amount; b <= y + amount; b++) {
- if (a < 0 || a >= imgWidth || b < 0 || b >= imgHeight) continue;
- int currentColor = colors[a][b];
- averageRed += Color.red(currentColor);
- averageGreen += Color.green(currentColor);
- averageBlue += Color.blue(currentColor);
- samples++;
- }
- }
- averageRed /= samples;
- averageGreen /= samples;
- averageBlue /= samples;
- editBitmap.setPixel(x, y, Color.argb(255, averageRed, averageBlue, averageGreen));
- }
- }
- return editBitmap;
Advertisement
Add Comment
Please, Sign In to add comment