Comparison between decodefiledescriptor () and bimap than decodefile ()

Source: Internet
Author: User

Key points:
1. Use decodefiledescriptor () to generate bimap, which saves memory than decodefile ().

Bitmap bmp = BitmapFactory.decodeFile(imageFile, opts);imageView.setImageBitmap(bmp);

Replace

1 FileInputStream is = = new FileInputStream(path);2 bmp = BitmapFactory.decodeFileDescriptor(is.getFD(), null, opts);

 

Cause:
View the bitmapfactory source code and compare the implementation of the two. We can find that decodefile () is used to generate bitmap in the form of a stream.

Decodefile source code:

 

 

 1 public static Bitmap decodeFile(String pathName, Options opts) { 2     Bitmap bm = null; 3     InputStream stream = null; 4     try { 5         stream = new FileInputStream(pathName); 6         bm = decodeStream(stream, null, opts); 7     } catch (Exception e) { 8         /*  do nothing. 9             If the exception happened on open, bm will be null.10         */11     } finally {12         if (stream != null) {13             try {14                 stream.close();15             } catch (IOException e) {16                 // do nothing here17             }18         }19     }20     return bm;21 }

 

Decodefiledescriptor source code, you can find the native local method decodefiledescriptor, generate bitmap through the underlying layer

Decodefiledescriptor source code:

 1 public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts) { 2        if (nativeIsSeekable(fd)) { 3            Bitmap bm = nativeDecodeFileDescriptor(fd, outPadding, opts); 4            if (bm == null && opts != null && opts.inBitmap != null) { 5                throw new IllegalArgumentException("Problem decoding into existing bitmap"); 6            } 7            return finishDecode(bm, outPadding, opts); 8        } else { 9            FileInputStream fis = new FileInputStream(fd);10            try {11                return decodeStream(fis, outPadding, opts);12            } finally {13                try {14                    fis.close();15                } catch (Throwable t) {/* ignore */}16            }17        }18    }19  20 private static native Bitmap nativeDecodeFileDescriptor(FileDescriptor fd,Rect padding, Options opts);

I can't give a reasonable explanation of what actually involves underlying virtual machines.

 

Comparison between decodefiledescriptor () and bimap than 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.