I've decoded an image from the gallery to a bitmap, and i'm using a blur class to blur the bitmap. (Error when trying to blur image using RenderScript support library on android phone)
I want to create a background from the blurred bitmap, but it's being stretched with this code (rl is my 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);
How to keep the bitmap's aspect ratio and scale it so it will cover both width and height of the device? Do I need to use an ImageView instead? How?