I use the following code to blur the image in android, but it does not work. The final image that I get has a very distorted color, not the blur that I want. What am I doing wrong?
public Bitmap blurBitmap(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight(); width = bmpOriginal.getWidth(); Bitmap bmpBlurred = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); for (int i = 1; i < width - 1; i++) { for (int j = 1; j < height - 1; j++) { int color = (int) getAverageOfPixel(bmpOriginal, i, j); bmpBlurred.setPixel(i, j, Color.argb(Color.alpha(color), Color.red(color), Color.green(color), Color.blue(color))); } } return bmpBlurred; } private double getAverageOfPixel(Bitmap bitmap, int i, int j) { return ( bitmap.getPixel(i-1, j-1) + bitmap.getPixel(i-1, j) + bitmap.getPixel(i-1, j+1) + bitmap.getPixel(i, j-1) + bitmap.getPixel(i, j) + bitmap.getPixel(i, j+1) + bitmap.getPixel(i+1, j-1) + bitmap.getPixel(i+1, j) + bitmap.getPixel(i+1, j+1)) / 9; }
source share