HBITMAP -> BITMAP

HBITMAP m_hBitmap = (HBITMAP)::LoadImage(NULL, pBitmapPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE/*(LR_LOADFROMFILE | LR_DEFAULTSIZE)*/);

 

BITMAP bm;

 

GetObject(hBitmap, sizeof(bm); &bm);

 

 

typedef   struct   tagBITMAP   {     //   bm    
        LONG       bmType;    
        LONG       bmWidth;    
        LONG       bmHeight;    
        LONG       bmWidthBytes;    
        WORD       bmPlanes;    
        WORD       bmBitsPixel;    
        LPVOID   bmBits;    
  }   BITMAP;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常抱歉,我之前提供的代码中确实存在错误。在调用 `bitmap->GetHBITMAP()` 函数时,需要传递一个 `ColorPalette` 对象作为参数。以下是修正后的代码: ```cpp // ... void OpenFile() { OPENFILENAME ofn; wchar_t szFile[MAX_PATH] = { 0 }; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = g_hWnd; ofn.lpstrFile = szFile; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = L"PNG文件\0*.png\0"; ofn.nFilterIndex = 1; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if (GetOpenFileName(&ofn)) { Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFile); if (bitmap->GetLastStatus() == Gdiplus::Ok) { if (g_hBitmap != NULL) { DeleteObject(g_hBitmap); } // 获取图像的宽度和高度 int width = bitmap->GetWidth(); int height = bitmap->GetHeight(); // 创建与图像大小相匹配的内存设备上下文 HDC hdcScreen = GetDC(NULL); HDC hdcMem = CreateCompatibleDC(hdcScreen); g_hBitmap = CreateCompatibleBitmap(hdcScreen, width, height); SelectObject(hdcMem, g_hBitmap); // 使用GDI+将图像绘制到内存设备上下文 Gdiplus::Graphics graphics(hdcMem); graphics.DrawImage(bitmap, 0, 0, width, height); // 释放资源 DeleteDC(hdcMem); ReleaseDC(NULL, hdcScreen); SendMessage(g_hImage, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)g_hBitmap); EnableWindow(g_hButtonSave, TRUE); } delete bitmap; } } // ... ``` 请注意,我们添加了一些代码来处理图像的宽度和高度,并创建与图像大小相匹配的内存设备上下文。这样可以确保在加载图像时保持其原始大小。 再次感谢您的指出,如果还有其他问题,请随时提问!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值