Windows Phone resolution image size-BMP Windows Phone resolution image size-gif

Source: Internet
Author: User
Tags bmp image

The section above describes how to parse gif images in Windows Phone, and how to parse jpg and png images. The image formats supported by Windows Phone are jpg and png. Therefore, the bmp image is similar to that displayed in GIF images. A third-party class library ImageTools is also required, the acquisition of imageils has been introduced in GIF Image Parsing. The following Code creates a control for displaying bmp images.

View Code

// Create a bmp Control
AnimatedImage BMP image = new AnimatedImage ();
Decoders. AddDecoder <BMP decoder> ();
// Load the Image Based on the byte stream of the image
ExtendedImage extendedImg = new ExtendedImage ();
BMP decoder dc = new BMP Decoder ();
Dc. Decode (extendedImg, stream );
BMP image. Source = extendedImg;

A typical bitmap file format usually contains the following data blocks:
  Bitmap header:Saves the overall information of a bitmap file.
  Bitmap information:Saves the detailed information of the bitmap image.
  Color Palette:Save 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 in bmp format, and the size information we need is stored in the bitmap information data block. Therefore, we need to know in detail the storage structure of the Bitmap header and bitmap information.
Bitmap header, which is the identification information, a typical application will first read this part of data to ensure that it is indeed a bitmap file and is not damaged.
Byte #0-1 stores the identifier of the bitmap file. The typical data of these two bytes isBM.
Byte #2-5 use a dword to save the bitmap file size.
Byte #6-9 is the reserved part, which will be used for future extension without affecting the actual decoding format.
Byte #10-13 stores the address offset of the bitmap data location, that is, the starting address.

Bitmap information, which tells the application of the detailed information of the image, the image displayed on the screen will use this information, it starts from the file's 15th bytes.
Byte #14-17 defines the size of the block (BitmapInfoHeader) used to describe the image. Its value is:40-Windows 3.2, 95, NT,12-OS/2 1.x, 240-OS/2 2.x
Bytes #18-21 Save the bitmap width (expressed in pixels ).
Bytes #22-25 Save the bitmap height (expressed in pixels ).
............
For more information about the bmp file structure, see http://zh.wikipedia.org/wiki/bmp in Wikipedia.
Through understanding the BMP image format, you can use the following code to parse the size of the bmp image.

View Code

// The first 2 bytes of the Bmp image: 0x42 4D
Byte [] header = new byte [2];
Stream. Read (header, 0, 2 );
If (! (Header [0] = 0x42 & header [1] = 0x4D ))
{
// The image is not a BMP Image
Return;
}

// Skip 16 bytes
Stream. Seek (16, SeekOrigin. Current );

// The width of the bmp image is 4 bytes at the position 18-21
// The Height Information of the bmp image is stored in the 22-25th 4 byte
// Read width, 4 bytes in height
Byte [] buffer = new byte [8];
Stream. Read (buffer, 0, buffer. Length );

Width _ = BitConverter. ToInt32 (buffer, 0 );
Height _ = BitConverter. ToInt32 (buffer, 4 );

 

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.