Compare the differences between Decodefiledescriptor and DecodeFile

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.