0

I am currently using device wallpaper as my layout background. The bitmap drawable size is very large on on some devices about 7 MB in Samsung S3. Is there any way to reduce this without consuming more RAM. I am worried about OOM on low memory devices.

WallpaperManager wallpaperManager = WallpaperManager.getInstance(mContext);
BitmapDrawable bitmapDrawable = (BitmapDrawable) wallpaperManager.getDrawable();
bitmapDrawable.setGravity(Gravity.CENTER_VERTICAL | Gravity.CLIP_VERTICAL);

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                layout.setBackgroundDrawable(bitmapDrawable);
} else {
                layout.setBackground(bitmapDrawable);
}

1 Answers1

0

you can use BitmapFactory.Options but should convert BitmapDrawable to byte[]

 //convert BitmapDrawable to byte[]
//winsize is height screen user device 
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options);
        if (options.outHeight >= (CampainManager.winSize )) {
            int x = (options.outHeight / (winSize ));
            options.inSampleSize = x;
        }
        options.inJustDecodeBounds = false;

        bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options);
yasser karimi
  • 329
  • 3
  • 13