首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在DIB上绘制不起作用

在DIB上绘制不起作用
EN

Stack Overflow用户
提问于 2017-05-21 01:47:04
回答 1查看 581关注 0票数 0

我正在开发一个GUI类,并且我创建了一个方法,该方法从像素数组在窗口上绘制位图。我想用同样的方法在那个位图上作画。另外,我使用屏幕外的DC来避免闪烁。

下面是我的代码:

代码语言:javascript
复制
int width(m_rect.right - m_rect.left), height(m_rect.bottom - m_rect.top); // m_rect is the RECT of the bitmap, initialized beforehand

BITMAPINFOHEADER bih = { 0 };
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biCompression = BI_RGB;
bih.biBitCount = 32;
bih.biPlanes = 1;
bih.biWidth = width; // = 100, for instance
bih.biHeight = height; // = 100, same here

HDC dc = CreateCompatibleDC(hdc); // "hdc" is the DC of my window
HBITMAP bmp = CreateDIBitmap(hdc, &bih, CBM_INIT, m_data, &m_bmpInfo, DIB_RGB_COLORS); // creates a 32-bit device-independent bitmap
HGDIOBJ oldObj = SelectObject(dc, bmp);

RECT r = { m_rect.left + 10, m_rect.top + 10, m_rect.right - 10, m_rect.bottom - 10 };
HBRUSH brush = CreateSolidBrush(0xff);
FillRect(dc, &r, brush); // this line doesn't work!
DeleteObject(brush);

BitBlt(hdc, m_rect.left, m_rect.top, width, height, dc, 0, 0, SRCCOPY);
SelectObject(dc, oldObj);
DeleteObject(bmp);
DeleteDC(dc);

问题是我不能在位图上画任何东西。它被正确地画在屏幕上,但我就是不能在上面画。与其他绘图函数相同: Rectangle,RoundRect等。另外,性能对我很重要。这段代码越快,我就越高兴。因此,如果您对性能改进有任何建议,请与我联系。

任何帮助都将不胜感激。提前谢谢你。

EN

回答 1

Stack Overflow用户

发布于 2019-08-22 15:53:30

CreateDIBitmap function CreateDIBitmap函数创建兼容的位图(DDB)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44089079

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档