admin管理员组文章数量:1221386
My question relates to a task I originally thought would be simple. I now find there are many details that were not first considered. My original goal was to draw an image of a flag in a dialog window. For simplicity I started just to display it in the main window. I started by finding a image, resizing it and storing it with my intended color depth. Bitmap / .BMP file seemed simple, that is what I intended to use. In my case four bit/sixteen color was selected to reduce the file size. The actual size in the file is 600 wide by 300 high. This gives a file with 90K pixel data plus the header which in my case is 118 bytes. As I am just learning windows API, I decided to do some initial tests. First I load the image using the following sequence... I removed the error checking for clarity:
hFlag = LoadImage(GetModuleHandle(NULL), wcImageFile,
IMAGE_BITMAP, 600, 300, LR_DEFAULTCOLOR | LR_LOADFROMFILE);
GetObject(hFlag, sizeof(BITMAP), &bitmap);
The content of bitmap is not what I expect after running this short sequence. The result for bmType, bmWidth, bmHeight, bmWidthBytes, bmPlanes are all as I expect. The bmBitsPixel however are 0x20 or 32. bmBits is a null pointer.
Something isn't right... LoadImage returns a handle to my bitmap without error. GetObject returns an int of 0x18 which is the size of the BITMAP structure it is filling. All as expected. Yet the bits per pixel which I expect to be 4 returns as 32. In a case of 32 bits/pixel the array size of pixel data will be short by eight times. This would likely be discovered and the null pointer generated.
Interesting also that if I later run:
SelectObject(hdcMem, hFlag);
BitBlt(hdc, 0, 0, 600, 300, hdcMem, 0, 0, SRCCOPY);
The flag is then displayed. I hope someone can help me make sense of this. I am working through Petzold however it's a big book.
Minimal example code...
case WM_CREATE:
{
const wchar_t *wImageFile;
wImageFile = L"C:\\Users\\Tom\\Pictures\\Flag\\Flag.bmp";
DWORD dwError = 0;
hFlag = (HBITMAP) LoadImage(GetModuleHandle(NULL), wImageFile, IMAGE_BITMAP, 600, 300, LR_DEFAULTCOLOR | LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if(hFlag == 0)
dwError = GetLastError();
int nWhatsit = GetObject(hFlag, sizeof(BITMAP), &bitmap);
return (INT_PTR)FALSE;
}
本文标签:
版权声明:本文标题:c++ - Display of a bitmap image, GetObject appears to incorrectly size some parameters in BITMAP structure - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739256848a2155174.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论