我正在开发一个GUI类,并且我创建了一个方法,该方法从像素数组在窗口上绘制位图。我想用同样的方法在那个位图上作画。另外,我使用屏幕外的DC来避免闪烁。
下面是我的代码:
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等。另外,性能对我很重要。这段代码越快,我就越高兴。因此,如果您对性能改进有任何建议,请与我联系。
任何帮助都将不胜感激。提前谢谢你。
发布于 2019-08-22 15:53:30
CreateDIBitmap function CreateDIBitmap函数创建兼容的位图(DDB)
https://stackoverflow.com/questions/44089079
复制相似问题