android - Shrink wallpaper bitmap drawable to reduce RAM usage -


i using device wallpaper layout background. bitmap drawable size large on on devices 7 mb in samsung s3. there way reduce without consuming more ram. worried 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); } 

you can use bitmapfactory.options should convert bitmapdrawable byte[]

 //convert bitmapdrawable byte[] //winsize 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); 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -