[英]Blur Image bitmap and set it as background
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.
基本上我试图实现的内容显示在这些图片中,它们只模糊 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;
}
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.我不希望 tp 将背景设置为渐变,而是作为该图像位图的模糊结果,就像我包含的图像一样。
There are many options:有很多选择:
Note: I didn't post any code because part of the solution is libraries or custom classes.注意:我没有发布任何代码,因为解决方案的一部分是库或自定义类。
Hope it helps.希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.