android - Bitmap in ListView: Loading slowly -
in listview, have 1 imageview , 2 textviews in every row. pictures listview loaded memory of galaxy nexus. downscaled 100x100 using
bitmap scaled = bitmap.createscaledbitmap(de, 80, 80, true); but still needs few seconds load.
what can do?
edit:
public bitmap resizebitmap(string path){ bitmapfactory.options options = new bitmapfactory.options(); inputstream = null; try { = new fileinputstream(path); } catch (filenotfoundexception e1) { // todo auto-generated catch block e1.printstacktrace(); } bitmapfactory.decodestream(is,null,options); try { is.close(); } catch (ioexception e1) { // todo auto-generated catch block e1.printstacktrace(); } try { = new fileinputstream(path); } catch (filenotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } // here w , h desired width , height options.insamplesize = math.max(options.outwidth/100, options.outheight/100); // bitmap resized bitmap bitmap bitmap = bitmapfactory.decodestream(is,null,options); return bitmap; }
first point can see code decoding stream twice...the first place decoded not being used anywhere....so removing statement increase execution speed of code.
//bitmapfactory.decodestream(is,null,options); comment line try { is.close(); } catch (ioexception e1) { // todo auto-generated catch block e1.printstacktrace(); } also may ask why can not use thumbnails of pictures? instead of resizing every image....if trying display thumbnails of images in app
yes there whole table stores thumbanil of images need access via cursor api example:
cursor mediacursor = managedquery( mediastore.images.media.external_content_uri, null, null, null, null); from cursor can imageid , of image id can retreive thumbnail of image using mediastore.images.thumbnails.getthumbnail() method example below code help:
bitmap thumbbitmap = null; thumbbitmap = mediastore.images.thumbnails.getthumbnail(cr, imageid, mediastore.images.thumbnails.micro_kind, null); if(thumbbitmap != null){ return new bitmapdrawable(thumbbitmap); }
Comments
Post a Comment