直接读文件,先读出BITMAPFILEHEADER结构, The BITMAPFILEHEADER structure contains information about the type, size, and layout of a file that contains a DIB. typedef struct tagBITMAPFILEHEADER { WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; } BITMAPFILEHEADER, *PBITMAPFILEHEADER; Members bfType Specifies the file type, must be BM. bfSize Specifies the size, in bytes, of the bitmap file. bfReserved1 Reserved; must be zero. bfReserved2 Reserved; must be zero. bfOffBits Specifies the offset, in bytes, from the BITMAPFILEHEADER structure to the bitmap bits. 然后再读出BITMAPINFO结构,里面就有高度和宽度了。 A BITMAPINFO or BITMAPCOREINFO structure immediately follows the BITMAPFILEHEADER structure in the DIB file.
hBitmapImag = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_BITMAP));
GetObject (hBitmapImag, sizeof (BITMAP), &bitmap) ;
cxBitmap = bitmap.bmWidth ;
cyBitmap = bitmap.bmHeight ;
The BITMAPFILEHEADER structure contains information about the type, size, and layout of a file that contains a DIB. typedef struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;
Members
bfType
Specifies the file type, must be BM.
bfSize
Specifies the size, in bytes, of the bitmap file.
bfReserved1
Reserved; must be zero.
bfReserved2
Reserved; must be zero.
bfOffBits
Specifies the offset, in bytes, from the BITMAPFILEHEADER structure to the bitmap bits. 然后再读出BITMAPINFO结构,里面就有高度和宽度了。
A BITMAPINFO or BITMAPCOREINFO structure immediately follows the BITMAPFILEHEADER structure in the DIB file.
"bitmap1.bmp",IMAGE_BITMAP,0,0,
LR_LOADFROMFILE);
楼上的很直接啊,直接可以得到我想要的结果~~
另外我想问句,加上“(HBITMAP)”有什么意义吗?我试着不加这个,也能运行啊~~