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;