Android Image decoding display process

Source: Internet
Author: User

Problem source Android can display internal stored images in gallery, support Jpeg,png,gif,bmp, and even file type and picture suffix name inconsistent, as long as the image file can be displayed, and then Git will only display the first frame of the image, but Android In fact, you can display GIF animation, in the browser open GIF animation, you can load the display normally.
Gallery View Picture Gallery implements the Gallery/src/com/android/camera/viewimage.java
                        Imageviewtouchbase Newview =                                mslideshowimageviews[mslideshowimagecurrent];                        Newview.setvisibility (view.visible);                        Newview.setimagerotatebitmapresetbase (bitmap, true);                        Newview.bringtofront ();

Load pictures and display them with your own implementation of the Imageviewtouchbase
Imageviewtouchbase inherits from the ImageView of the framework
Package Com.android.camera;import Android.content.context;import Android.graphics.bitmap;import Android.graphics.matrix;import Android.graphics.rectf;import Android.graphics.drawable.drawable;import Android.os.handler;import Android.util.attributeset;import Android.view.keyevent;import Android.widget.ImageView; Abstract class Imageviewtouchbase extends ImageView {

Framework processing picture ImageView is an Android picture framework that implements a generic image processing display class: Can display resource inside the picture,
    public void Setimageresource (int resId) {        if (MUri! = NULL | | Mresource! = resId) {            updatedrawable (null);            Mresource = resId;            MUri = null;            Final int oldwidth = mdrawablewidth;            Final int oldheight = mdrawableheight;            ResolveUri ();            if (oldwidth! = Mdrawablewidth | | OldHeight! = mdrawableheight) {                requestlayout ();            }            Invalidate ();        }    }

The images we opened in gallery are sent through a URI,
    public void Setimageuri (Uri uri) {        if (mresource! = 0 | |                (MUri! = URI &&                 (URI = = NULL | | mUri = NULL | |!uri.equals (MURI)))) {            updatedrawable (null);            Mresource = 0;            MUri = URI;            Final int oldwidth = mdrawablewidth;            Final int oldheight = mdrawableheight;            ResolveUri ();            if (oldwidth! = Mdrawablewidth | | OldHeight! = mdrawableheight) {                requestlayout ();            }            Invalidate ();        }    }

Android will parse URI to get destination file path
        } else if (MUri! = null) {String scheme = Muri.getscheme (); if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals (SCHEME)) {try {//Load drawable THR                            Ough Resources, to get the source density information Contentresolver.openresourceidresult r =                    Mcontext.getcontentresolver (). Getresourceid (MUri);                D = r.r.getdrawable (r.id);                } catch (Exception e) {LOG.W ("ImageView", "Unable to open content:" + MUri, E); }} else if (ContentResolver.SCHEME_CONTENT.equals | |                ContentResolver.SCHEME_FILE.equals (SCHEME)) {InputStream stream = null;                    try {stream = Mcontext.getcontentresolver (). Openinputstream (MUri);                D = Drawable.createfromstream (stream, NULL); } catch (Exception e) {LOG.W ("ImageviEW "," Unable to open content: "+ MUri, E); } finally {if (stream! = null) {try {stream.close (                        );                        } catch (IOException e) {LOG.W ("ImageView", "Unable to close content:" + MUri, E); }}}} else {d = Drawable.createfrompath (muri.tost            Ring ()); }

We click on gallery image to generate Uri:i/activitymanager (1304) containing content: START u0 {dat= content://media/external/images/media/21 cmp=com.android.gallery/com.android.camera.viewimage (have extras)} from PID 1706

The Drawable object is then parsed from the InputStream with drawable
    public static drawable Createfromstream (InputStream is, String srcname) {        Trace.tracebegin (trace.trace_tag_ RESOURCES, SrcName! = null? SrcName: "Unknown drawable");        try {            return createfromresourcestream (NULL, NULL, is, srcname, null);        } finally {            trace.traceend ( trace.trace_tag_resources);        }    }

The next process is to give the Skia parse and then get a bitmap and return. The Skia decode automatically identifies the data stream inside the steam to create the corresponding decoder. The answer framework is a generic picture display processing, and finally only returns a bitmap, so GIF can only handle the first frame of the image, but browser is a new implementation of the image display interface, there is a special display processing for GIF, so you can display the animation.

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.