Load many large bitmap images as thumbnails - Android -


i'm working on media player app , wish load album art images display in listview. right works fine images i'm auto-downloading last.fm under 500x500 png's. however, added panel app allows viewing full screen artwork i've replaced of artworks large (1024x1024) png's instead.

now when scroll on several albums high res artwork, java.lang.outofmemoryerror on bitmapfactory.

    static public bitmap getalbumartfromcache(string artist, string album, context c)     {     bitmap artwork = null;     file dirfile = new file(sourcelistoperations.getalbumartpath(c));     dirfile.mkdirs();     string artfilepath = sourcelistoperations.getalbumartpath(c) + file.separator + sourcelistoperations.makefilename(artist) + "_" + sourcelistoperations.makefilename(album) + ".png";     file infile = new file(artfilepath);     try     {         artwork = bitmapfactory.decodefile(infile.getabsolutepath());     }catch(exception e){}     if(artwork == null)     {         try         {             artwork = bitmapfactory.decoderesource(c.getresources(), r.drawable.icon);         }catch(exception ex){}     }     return artwork;     } 

is there can add limit size of resulting bitmap object say, 256x256? that's bigger thumbnails need , make duplicate function or argument fetch full size artwork displaying full screen.

also, i'm displaying these bitmaps on imageviews small, around 150x150 200x200. smaller images scale down nicer large ones do. there way apply downscaling filter smooth image (anti-aliasing perhaps)? don't want cache bunch of additional thumbnail files if don't have to, because make managing artwork images more difficult (currently can dump new ones in directory , automatically used next time loaded).

the full code @ http://github.org/calcprogrammer1/calctunes, in src/com/calcprogrammer1/calctunes/albumartmanager.java, though there's not different in other function (which falls checking last.fm if image missing).

i use private function setup size want thumbnails:

//decodes image , scales reduce memory consumption public static bitmap getscaledbitmap(string path, int newsize) {     file image = new file(path);      bitmapfactory.options options = new bitmapfactory.options();     options.injustdecodebounds = true;     options.ininputshareable = true;     options.inpurgeable = true;      bitmapfactory.decodefile(image.getpath(), options);     if ((options.outwidth == -1) || (options.outheight == -1))         return null;      int originalsize = (options.outheight > options.outwidth) ? options.outheight             : options.outwidth;      bitmapfactory.options opts = new bitmapfactory.options();     opts.insamplesize = originalsize / newsize;      bitmap scaledbitmap = bitmapfactory.decodefile(image.getpath(), opts);      return scaledbitmap;      } 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -