Windows Phone resolution image size gif

Source: Internet
Author: User

We have introduced the size resolution of PNG and jpg images. Windows Phone directly supports the display of these two images and uses the Image control. GIF images need to be displayed using third-party controls. ImageTools is provided by CodePlex In the open-source community. You can download dllwith the source code through http://imagetools.codeplex.com.
After referencing the ImageTools class library, you can use the following code to display GIF images.

View Code

// Create a gif Control
AnimatedImage gifImage = new AnimatedImage ();
Decoders. AddDecoder <GifDecoder> ();
// Load the Image Based on the byte stream of the image
ExtendedImage extendedImg = new ExtendedImage ();
GifDecoder dc = new GifDecoder ();
Dc. Decode (extendedImg, stream );
GifImage. Source = extendedImg;

The format of the GIF image file is relatively simple. The width and height information are stored in the first four bytes of the logical video description block, while the logical video description block is the second area of the GIF image, the first region contains 6 bytes of headers, including identifiers and versions. The following table lists the descriptions of each byte until the height information.

Name Bytes Description
Header    
Identifier 3 GIF 47 49 46
Version 3 87a (89a) 38 39 | 37 61
Logical video description block    
Width 2  
Height 2  

According to the preceding format, it is easy to obtain the image height and width. The specific code is as follows.

View Code

// GIF Image Information Field (47 49 46 38 39 | 37 61) GIF89 (7) a, 6 bytes in total
// Determine whether the image is a GIF Image Based on 6 bytes
Byte [] header = new byte [6];
Stream. Read (header, 0, 6 );
If (! (Header [0] = 0x47 & // G
Header [1] = 0x49 & // I
Header [2] = 0x46 & // F
Header [3] = 0x38 & // 8
(Header [4] = 0x39 | // 9
Header [4] = 0x37) & // 7
Header [5] = 0x61) //
{
// Exit if the image is not a GIF Image
Return;
}

// Read width, 2 bytes in height
Byte [] buffer = new byte [4];
Stream. Read (buffer, 0, buffer. Length );

Width _ = BitConverter. ToInt16 (buffer, 0 );
Height _ = BitConverter. ToInt16 (buffer, 2 );

 

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.