Obtain the bitmap size.

Source: Internet
Author: User

 

 

ForCBitmap object. We can use the GetBitmap () function to determine its width and height.

 

// The variable bitmap is a CBitmap object bitmap variable is a CBitmap object

BITMAP bm;

Bitmap. GetBitmap (& bm );

BmWidth = bm. bmWidth;

BmHeight = bm. bmHeight;

 

If you haveHBITMAP bitmap handle. You can attach it to a CBitmap object, and then use the method mentioned above or the following method to determine its width and height.

 

// The variable hBmp is a HBITMAPThe hBmp variable is an HBITMAP bitmap handle.

BITMAP bm;

: GetObject (hBmp, sizeof (bm), & bm );

BmWidth = bm. bmWidth;

BmHeight = bm. bmHeight;

 

You can use the following code to implement an object:

 

CFile file;

// SBMPFileName is the BMP filenameSBMPFileName is a bitmap file name.

If (! File. Open (sBMPFileName, CFile: modeRead ))

Return;

 

BITMAPFILEHEADER bmfHeader;

 

// Read file headerRead File Header Information

If (file. Read (LPSTR) & bmfHeader, sizeof (bmfHeader ))! = Sizeof (bmfHeader ))

Return;

 

// File type shocould be BMDetermine the file type

If (bmfHeader. bfType! = (WORD) (M <8) | B ))

Return;

 

BITMAPINFOHEADER bmiHeader;

If (file. Read (LPSTR) & bmiHeader, sizeof (bmiHeader ))! = Sizeof (bmiHeader ))

Return;

 

 

Int bmWidth = bmiHeader. biWidth;

Int bmHeight = bmiHeader. biHeight;

 

 

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.