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/