Windows Phone parsing gif of picture size

Source: Internet
Author: User

The dimensions of PNG and JPG images are described earlier, and Windows phone supports the display of both pictures directly, using the image control. GIF pictures need to be developed by a third party control to display, Imagetools is open source community CodePlex provided by the http://imagetools.codeplex.com/download DLL and source code.

After referencing the Imagetools class library, you can display the GIF picture with the following code.

Create a GIF control
        animatedimage gifimage = new Animatedimage ();
        Decoders.adddecoder<gifdecoder> ();
        Load pictures According to the picture byte stream
        extendedimage extendedimg = new Extendedimage ();
        Gifdecoder dc = new Gifdecoder ();
        dc. Decode (extendedimg, stream);
        Gifimage.source = extendedimg;

The file format for GIF pictures is relatively simple, where the width and height information is stored in the first 4 bytes of the logical screen description block, while the logical visual description block is the second area of the GIF image, the first area is a 6-byte head, and the header includes an identifier and a version. The following table lists the descriptions of the individual bytes, up to the height information.

Depending on the format above, it is easy to get the height and width information of the picture, as shown in the code below.

GIF picture information domain (39|37) GIF89 (7) A, total 6 bytes
        ///Based on 6 bytes for GIF picture
        byte[] Header = new byte[6];
        Stream. Read (header, 0, 6);
        if (!) ( Header[0] = = 0x47 &&       /G
                header[1] = = 0x49 &&    //I
                header[2] = = 0x46 &&    //f< C10/>HEADER[3] = = 0x38 &&    //8
                (header[4] = = 0x39 | |   9
                header[4] = = 0x37) &&   /7
                header[5] = = 0x61))     //a
        {/
            /not GIF picture, exit
            return;
        }
    
        Read width, height each 2 bytes
        byte[] buffer = new BYTE[4];
        Stream. Read (buffer, 0, buffer.) Length);
    
        Width_ = bitconverter.toint16 (buffer, 0);
        Height_ = bitconverter.toint16 (buffer, 2);

Author: Yu Le

Source: http://www.cnblogs.com/huizhang212/

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

Related Article

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.