1

is there any systemical possible way (i mean in code) to make a blur background depends on the image user open, the color must be similar to the image that will open.

for example, the background on this page is grey.

enter image description here

Arash Afsharpour
  • 1,282
  • 11
  • 22

2 Answers2

3

You will need to get the dominant color from the image you are using then create a gradient drawable between a starting color and your dominant color. There are multiple ways to find dominant colors which you can read up on here: Finding the dominant color of an image in an Android @drawable

From there you create a drawable and set the background of your view to that drawable:

    // get the drawable from the image view
    // could also be pulled from resources if available
    Bitmap bm=((BitmapDrawable)imageView.getDrawable()).getBitmap();

    int color = getDominantColor(bm);

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

    contentView.setBackground(gradient);
SRoseDev88
  • 184
  • 6
  • im using their code and it gave me black square background, where should i put your code? im a little bit confused... [link](https://preview.ibb.co/jYe0MR/1.jpg) and this is my code – Arash Afsharpour Oct 28 '17 at 20:00
  • I used the method that created a scaled bitmap as a 1x1 image and extracted the color from that, it's less overhead than the pallet library for this simple of a task. As for where I put my code, it was in my onCreate of the activity. The image view source was set in the XML for my testing, if you're setting the source dynamically then pass the same image to the method. – SRoseDev88 Oct 29 '17 at 00:55
1

See this library to make blur image https://github.com/wasabeef/Blurry

Imene Noomene
  • 3,035
  • 5
  • 18
  • 34