在MFC中创建DIBSection并使用图片控件进行渲染

发布于 2024-10-18 04:01:38 字数 1624 浏览 12 评论 0原文

我使用调用 CreateDIBSection 在 MFC 中创建 DIB 部分。我从调用中获得一个 HBITMAP,并将其传递到 MFC 项目中的另一个对话框。在另一个对话框中,我使用 CStatic::SetBitmap(HBITMAP) 调用来渲染位图。但由于某种原因我看不到任何东西。如果这是在同一个对话框中完成的,那么效果非常好,但我想在一个对话框中创建位图并在另一个对话框中显示。

创建 DIBSection 的代码是

//-----------------BEGINNING OF FIRST DIALOG--------------------------------------------------

 LPVOID pViewBitmapBits = NULL;

   BITMAPINFOHEADER BMHeaderInfo;
   memset(&BMHeaderInfo, 0, sizeof(BITMAPINFOHEADER));
   BMHeaderInfo.biSize        = sizeof(BITMAPINFOHEADER);
   BMHeaderInfo.biWidth       = 800;
   BMHeaderInfo.biHeight      = 400;
   BMHeaderInfo.biPlanes      = 1;
   BMHeaderInfo.biBitCount    = 8;
   BMHeaderInfo.biCompression = BI_RGB;
   BMHeaderInfo.biSizeImage   = 0;
   BMHeaderInfo.biClrUsed     = 0;
   BMHeaderInfo.biClrImportant= 0;



   BITMAPINFO BMInfo;
   memset(&BMInfo, 0, sizeof(BMInfo));
   BMInfo.bmiHeader = BMHeaderInfo;
   BMInfo.bmiColors[0].rgbBlue=255;




  HBITMAP hGlobalBitMap = CreateDIBSection(m_pParentSheet->test.m_hDC, &BMInfo, DIB_RGB_COLORS, &pViewBitmapBits, NULL, NULL);
   SelectObject(m_pParentSheet->test.m_hDC, hGlobalBitMap);

//--------------------------END OF FIRST DIALOG----------------------------------


//-----------------------------BEGINNING OF SECOND DIALOG----------------------------------------

void CreateViewDlg::OnBnClickedButton2()

{

   m_pic.SetBitmap(hGlobalBitMap );

}

//------------------------------------END OF SECOND DIALOG---------------------------------

Please help me with this。 HBITMAP 句柄的使用有任何限制吗?

I'm creating a DIB Section in MFC using the call CreateDIBSection. I get a HBITMAP from the call which I pass onto another dialog in my MFC Project. In the other dialog I'm using CStatic::SetBitmap(HBITMAP) call to render the bitmap. But for some reason I'm not able to see anything. This works perfectly fine if this is done in same dialog, but I want to create bitmap in one dialog and display in another.

The code for creating the DIBSection is

//-----------------BEGINNING OF FIRST DIALOG--------------------------------------------------

 LPVOID pViewBitmapBits = NULL;

   BITMAPINFOHEADER BMHeaderInfo;
   memset(&BMHeaderInfo, 0, sizeof(BITMAPINFOHEADER));
   BMHeaderInfo.biSize        = sizeof(BITMAPINFOHEADER);
   BMHeaderInfo.biWidth       = 800;
   BMHeaderInfo.biHeight      = 400;
   BMHeaderInfo.biPlanes      = 1;
   BMHeaderInfo.biBitCount    = 8;
   BMHeaderInfo.biCompression = BI_RGB;
   BMHeaderInfo.biSizeImage   = 0;
   BMHeaderInfo.biClrUsed     = 0;
   BMHeaderInfo.biClrImportant= 0;



   BITMAPINFO BMInfo;
   memset(&BMInfo, 0, sizeof(BMInfo));
   BMInfo.bmiHeader = BMHeaderInfo;
   BMInfo.bmiColors[0].rgbBlue=255;




  HBITMAP hGlobalBitMap = CreateDIBSection(m_pParentSheet->test.m_hDC, &BMInfo, DIB_RGB_COLORS, &pViewBitmapBits, NULL, NULL);
   SelectObject(m_pParentSheet->test.m_hDC, hGlobalBitMap);

//--------------------------END OF FIRST DIALOG----------------------------------


//-----------------------------BEGINNING OF SECOND DIALOG----------------------------------------

void CreateViewDlg::OnBnClickedButton2()

{

   m_pic.SetBitmap(hGlobalBitMap );

}

//------------------------------------END OF SECOND DIALOG---------------------------------

Please help me with this. Is there any limitation to the usage of HBITMAP Handles?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你不是我要的菜∠ 2024-10-25 04:01:38
HBITMAP hGlobalBitMap = ...

看起来像局部变量隐藏了全局变量。

HBITMAP hGlobalBitMap = ...

Looks like local variable hiding the global variable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文