【发布时间】:2014-08-09 17:21:20
【问题描述】:
我已将图库中的图像解码为位图,并且我正在使用模糊类来模糊位图。 (Error when trying to blur image using RenderScript support library on android phone)
我想从模糊的位图创建一个背景,但它被这段代码拉伸了(rl 是我的 RelativeLayout):
Uri selectedImageUri = data.getData();
Blur blur = new Blur();
imagepath = getRealPathFromURI(selectedImageUri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imagepath, options);
int pow = 0;
while (options.outHeight >> pow > options.outHeight / 2 || options.outWidth >> pow > options.outWidth / 2) {
pow += 1;
options.inSampleSize = 1 << pow;
options.inJustDecodeBounds = false;
}
Bitmap bmImg = BitmapFactory.decodeFile(imagepath, options);
Bitmap BlurredIMG = Blur.doBlur(bmImg, 33, false);
BitmapDrawable bmp = new BitmapDrawable(BlurredIMG);
rl.setBackground(bmp);
如何保持位图的纵横比并对其进行缩放以覆盖设备的宽度和高度? 我需要改用 ImageView 吗?怎么样?
【问题讨论】:
标签: android bitmap background drawable