如何制作模糊背景取决于您在 Android 中加载的图像颜色

How to make a Blur background depends on the Image color that you are loading in Android

是否有任何系统性的方法(我的意思是在代码中)根据用户打开的图像制作模糊背景,颜色必须与将打开的图像相似。

比如这个页面的背景是灰色的。

查看这个库来制作模糊图像https://github.com/wasabeef/Blurry

您需要从正在使用的图像中获取主色,然后在起始色和主色之间创建可绘制的渐变。有多种方法可以找到主色,您可以在此处阅读:Finding the dominant color of an image in an Android @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);