From the local reading pictures, you can use Decodefiledescriptor and DecodeFile, as to which way the memory consumption situation made a simple comparison, may choose 6 pictures at once too little, seemingly different, Decodefiledescriptor can save around 1.6MB:
1, Decodefiledescriptor read 6 pictures (middle contains compression, read, turn Base64)
2, DecodeFile read 6 pictures (middle contains compression, read, turn Base64)
Public StaticBitmap Decodesampledbitmapfromfile (String filepath,intReqwidth,intreqheight) { FinalBitmapfactory.options Options =Newbitmapfactory.options (); Options.injustdecodebounds=true; FileInputStream is=NULL; Bitmap Bitmap=NULL; Try{ is=NewFileInputStream (filepath); Bitmapfactory.decodefiledescriptor (Is.getfd (),NULL, Options); } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); } options.insamplesize=calculateinsamplesize (options, reqwidth,reqheight); Options.injustdecodebounds=false; Try{bitmap= Bitmapfactory.decodefiledescriptor (Is.getfd (),NULL, Options); } Catch(IOException e) {e.printstacktrace (); }finally { if(Is! =NULL) { Try{is.close (); } Catch(IOException e) {// do nothing here } } } returnbitmap; }
Public StaticBitmap DecodeSampledBitmapFromFile2 (String filepath,intReqwidth,intreqheight) { FinalBitmapfactory.options Options =Newbitmapfactory.options (); Options.injustdecodebounds=true; Bitmapfactory.decodefile (filepath, options); Options.insamplesize=calculateinsamplesize (options, reqwidth,reqheight); Options.injustdecodebounds=false; returnbitmapfactory.decodefile (filepath, options); }
A comparison of 50 more pictures:
Decodefiledescriptor altogether used 34MB.
DecodeFile triggers gcc to automatically reclaim memory??
Here's a look back at the compression-treated code:
for(inti=0; I<mselectpath.size (); i++) {String path=Mselectpath.get (i); //compression processing (hints required)Bitmap Bitmap =Pictureutil.decodesampledbitmapfromfile (path,myconfig.picmaxwidth,myconfig.picmaxheight); //Save the picture to the appropriate folder (the quality may become worse)//pictureutil.savebitmapwithcompress (bitmap,50,fileslist); if(!bitmap.isrecycled ()) {bitmap.recycle (); //Reclaim the memory of a pictureSystem.GC ();//Alert System for timely recovery } }
By adding bitmap memory reclaim and release:
The use of Decodefiledescriptor is as follows:
This is only used for 16MB
Compare the differences between Decodefiledescriptor and DecodeFile