The Windows Phone resolution GIF for image size is described earlier, as well as the related parsing of JPG and PNG pictures. Windows phone system supports the image format is JPG and PNG, so the reality of BMP pictures and GIF image display similar to the way the processing, the same need to adopt Third-party class library Imagetools, where the imagetools in GIF image parsing has been introduced, The following code shows a control that creates a BMP picture.
Create a BMP control
animatedimage bmpimage = new Animatedimage ();
Decoders.adddecoder<bmpdecoder> ();
Load pictures According to the picture byte stream
extendedimage extendedimg = new Extendedimage ();
Bmpdecoder dc = new Bmpdecoder ();
dc. Decode (extendedimg, stream);
Bmpimage.source = extendedimg;
A typical bitmap file format typically contains the following blocks of data:
Bitmap headers: Saves the overall information for a bitmap file.
Bitmap information: Saves the detailed information of a bitmap image.
Palette: Saves the definition of the color used.
Bitmap data: Saves the actual image of one pixel after another.
By parsing the bitmap header we can determine whether the image is BMP format, and we need the picture size information stored in the bitmap information block. So we need to learn more about bitmap headers and bitmap information in the storage structure of two blocks of data.
Bitmap headers, which are part of identifying information, typically the application will first read this part of the data to make sure it is a bitmap file and is not corrupted.
BYTE #0-1 to save the identifier of the bitmap file, which is the typical two-byte data is BM.
BYTE #2-5 uses a DWORD to save the bitmap file size.
The byte #6-9 is the reserved part, which is retained for later extension use, and has no effect on the actual decoding format.
BYTE #10-13 The address offset of the location where the bitmap data is saved, which is the starting address.
Bitmap information, which tells the application the details of the image, which will be used to display the image on the screen, starting with the 15th byte of the file.
The byte #14-17 defines the size of the block (Bitmapinfoheader) to describe the image below. Its value is: 40-windows 3.2, 95, NT, 12-OS/2 1.x, 240-OS/2 2.x
BYTE #18-21 to preserve the width of the bitmap, expressed as a number of pixels.
BYTE #22-25 Saves the bitmap height (in pixels).
............
The above content about BMP file structure refer to Wikipedia Http://zh.wikipedia.org/wiki/BMP.
Through the above to BMP picture format understanding, you can use the following code to resolve BMP picture size.
Bmp picture before 2 bytes: 0x42 4D
byte[] Header = new byte[2];
Stream. Read (header, 0, 2);
if (!) ( Header[0] = = 0x42 && header[1] = = 0x4d)
{
//not BMP picture return
;
}
Skips 16 byte
stream. Seek (seekorigin.current);
BMP picture Width information stored in the 第18-21位 4
-byte//bmp picture of the degree of information saved in 第22-25位 4 bytes
/read width, height of 4 bytes
byte[] buffer = new BYTE[8];
Stream. Read (buffer, 0, buffer.) Length);
Width_ = bitconverter.toint32 (buffer, 0);
Height_ = Bitconverter.toint32 (buffer, 4);
Author: Yu Le
Source: http://www.cnblogs.com/huizhang212/
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/