如何绘制位图
首先:我对 GDI 有点陌生,所以如果我有任何误解,请原谅(并让我知道)。
我想做的事情: 我试图让我的 WM_PAINT 代码绘制位图而不是使用 BeginPaint() 绘制到屏幕。我还想在屏幕上显示位图,同时在其顶部显示其他数据(不会保存到位图)。
谁能告诉我实现此目的所需的 win32 函数和数据类型? 谢谢
First of all: I'm sort of new to GDI, so please excuse me (and do let me know) if I make any misconceptions.
What I'm trying to do:
I'm trying to let my WM_PAINT code paint to a bitmap instead of to the screen with BeginPaint(). I would also like to display the bitmap on the screen while also displaying other data on top of it(that doesn't get saved to the bitmap).
Could anyone tell me the win32 functions and datatypes needed to achieve this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,要在窗户以外的地方绘画,您需要一个新的 DC。您可以使用 HDC memDC = CreateCompatibleDC([your window hdc]); 来创建一个。
现在您需要一个位图来绘制。使用 HBITMAP memBitmap = CreateCompatibleBitmap ([您的窗口 hdc],[您的窗口宽度],[您的窗口高度]); (假设您想要一个相同的尺寸,如果不是,则
StretchBlt
应该可以做到这一点)来创建它。请注意,使用完这些后,您需要
DeleteObject (memBitmap);
和DeleteDC (memDC);
进行清理。创建后,通过
SelectObject (memDC, memBitmap); 将位图选择到屏幕外 DC;
现在将所有绘图操作到
memDC
。完成后,使用BitBlt()
函数,将源 hdc 作为 memDC,将目标 hdc 作为窗口的 DC。不要忘记删除您创建的内容。First of all, to paint somewhere other than your window, you'll need a new DC. You can use
HDC memDC = CreateCompatibleDC([your window hdc]);
to create one.Now you'll need a bitmap to paint to. Use
HBITMAP memBitmap = CreateCompatibleBitmap ([your window hdc],[your window width],[your window height]);
(assuming you want one the same size, if it isn't thenStretchBlt
should do the trick) to create that.Note that when you're done using these you'll need to
DeleteObject (memBitmap);
andDeleteDC (memDC);
to clean up.Once created, select the bitmap into your offscreen DC via
SelectObject (memDC, memBitmap);
Now do all of your drawing to
memDC
. Once finished, use theBitBlt()
function with source hdc as memDC and destination hdc as your window's DC. Don't forget to delete what you created.