【问题标题】:Blur Image bitmap and set it as background模糊图像位图并将其设置为背景
【发布时间】:2019-08-15 13:53:53
【问题描述】:

我一直在尝试模糊图像视图并将整个布局的背景设置为模糊位图,但无济于事。基本上我想要达到的效果显示在这些图片中,它们只模糊 imageView 并将扩展的模糊图像设置为布局背景。

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;
}

我不希望将背景设置为渐变,而是作为该图像位图的模糊结果,就像在我包含的图像中一样。

【问题讨论】:

    标签: java android imageview blur blurry


    【解决方案1】:

    有很多选择:

    1. 您可以放大然后缩小位图。这样做是减少产生类似模糊效果的图片数量。如果您想这样做,请参见此处:Fast Bitmap Blur For Android SDK。但是,它的内存效率不是很高,如果它像这样工作,您可能需要更改您的实现。
    2. 使用预制库。有许多库,其中一些比其他库更好,可让您模糊位图。制作这些库的人已经在减少内存使用和更好的兼容性方面做了艰苦的工作。这里也有一个例子:Fast Bitmap Blur For Android SDK

    注意:我没有发布任何代码,因为部分解决方案是库或自定义类。

    希望对你有帮助。

    【讨论】:

    • 好的。我刚刚看到了一个名为 Blurry 的库。让我试一试,然后回复你。感谢您的快速回复
    • 对您有帮助吗?
    猜你喜欢
    • 2020-02-04
    • 1970-01-01
    • 2013-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多