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 );