Scaling Icon to fit in Imageview Android -


i have list in application contains installed applications icons, i'm able render installed applications , icons consuming lot of memory loads drawables(icons) of installed applications memory well.

i want scale down icon , load memory reduce memory usage of application. can tell me how can achieved.

note : if png format not compress image because png lossless format. , applications icons in png format

any way reduce memory allocation icons??

yeah it's in docs:

http://developer.android.com/training/displaying-bitmaps/index.html

calculate sample size, i.e. size of bitmap want:

public static int calculateinsamplesize(             bitmapfactory.options options, int reqwidth, int reqheight) {     // raw height , width of image     final int height = options.outheight;     final int width = options.outwidth;     int insamplesize = 1;      if (height > reqheight || width > reqwidth) {          // calculate ratios of height , width requested height , width         final int heightratio = math.round((float) height / (float) reqheight);         final int widthratio = math.round((float) width / (float) reqwidth);          // choose smallest ratio insamplesize value, guarantee         // final image both dimensions larger or equal         // requested height , width.         insamplesize = heightratio < widthratio ? heightratio : widthratio;     }      return insamplesize; } 

the decode bitmap @ size:

public static bitmap decodesampledbitmapfromresource(resources res, int resid,         int reqwidth, int reqheight) {      // first decode injustdecodebounds=true check dimensions     final bitmapfactory.options options = new bitmapfactory.options();     options.injustdecodebounds = true;     bitmapfactory.decoderesource(res, resid, options);      // calculate insamplesize     options.insamplesize = calculateinsamplesize(options, reqwidth, reqheight);      // decode bitmap insamplesize set     options.injustdecodebounds = false;     return bitmapfactory.decoderesource(res, resid, options); } 

this should done off ui thread:

http://developer.android.com/training/displaying-bitmaps/process-bitmap.html

you can cache bitmaps don't have more times necessary:

http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -