quite simple questions, can't find answer..
i'm asking in order know if though imageview shows smaller version of original image - still use full memory size of original .. ? (i refer image loaded sd-card , not resources)
yes, use original size. have resize bitmaps before assign imageview, otherwise have lot of problems out of memory error.
you should calculate final size of imageview , resize bitmap.
some code going.
private static bitmap createbitmap(@nonnull string filepath, int width ) { bitmapfactory.options options = new bitmapfactory.options(); options.injustdecodebounds = true; bitmapfactory.decodefile(filepath , options ); // getting original image properties int imageheight = options.outheight; int imagewidth = options.outwidth; int scale = -1; if ( imagewidth < imageheight ) { scale = math.round( imageheight / width ); } else { scale = math.round(imagewidth / width); } if ( scale <= 0 ) scale = 1; options.insamplesize = scale; options.injustdecodebounds = false; // create resized bitmap bitmap scaledbitmap = bitmapfactory.decodefile(filepath , options); return scaledbitmap; } you should consider:
- maintain bitmap operations outside main thread.
- handle concurrency correctly
- make use of open source lib, one
Comments
Post a Comment