-2

I have been trying to blur an imageview and set the background of the whole layout to the blurred bitmap to no avail. Basically what am trying to achieve is shown in these pictures, where they only blur the imageView and set the expanded blurred image as the layout background.

enter image description here

enter image description here

int color = getDominantColor(bitmap); //get dominant color of the bitmap

 //create gradient
                GradientDrawable gradient = new GradientDrawable(
                        GradientDrawable.Orientation.TOP_BOTTOM,
                        new int[] {0xf5f5f5,color});
                gradient.setCornerRadius(0f);

                //setbackground of the relativelayout
                rl.setBackground(gradient);//rl is relative layout





  //getting dominant color of bitmap
public static int getDominantColor(Bitmap bitmap) {
    Bitmap newBitmap = Bitmap.createScaledBitmap(bitmap, 1, 1, true);
    final int color = newBitmap.getPixel(0, 0);
    newBitmap.recycle();
    return color;
}

I dont want tp set the background as a gradient, but as the blurred result of that image bitmap, just like in the images i've included.

James Z
  • 12,209
  • 10
  • 24
  • 44
Ezra Raleigh
  • 61
  • 12

1 Answers1

0

There are many options:

  1. You can enlarge and then downscale the bitmap. What that does is decrease the number of pictures producing something like the effect of blurring. See here if you want to do that: Fast Bitmap Blur For Android SDK. However, it isn't very memory efficient and you may want to change your implementation if it works like this.
  2. Use a pre-made library. There are many libraries, some better than others, allowing you to blur bitmaps. The people who made these libraries have already done the hard job at reducing memory usage and better compatibility. An example is also here: Fast Bitmap Blur For Android SDK

Note: I didn't post any code because part of the solution is libraries or custom classes.

Hope it helps.

Gaurav Mall
  • 2,372
  • 1
  • 17
  • 33