Android Blur

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; } 
+3
source share
1 answer

Your problem is that you combine all the color channels at the same time, and they all spill out into each other. You must apply the blur function to the red, green and blue channels separately.

Could it be easier to create a SurfaceView and use the FX_SURFACE_BLUR flag?

+2
source

Source: https://habr.com/ru/post/906819/


All Articles