在C ++中快速在窗口中移动位图 [英] Move a bitmap around a window quickly in C++

查看:41
本文介绍了在C ++中快速在窗口中移动位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些C ++代码,以使我可以在窗口中快速移动位图,并在移动时恢复背景.目前,我在应用程序初始化期间将Window内容捕获到位图中,并在OnPaint()中绘制了该位图,然后绘制了覆盖的位图.我正在双重缓冲油漆.叠加的位图位置随鼠标移动,从而使窗口无效.

I'm looking for some C++ code to let me quickly move a bitmap around a window, restoring the background as it moves. At present I capture the Window contents to a bitmap during the app initialization and in the OnPaint() I draw the this bitmap and then I draw my overlayed bitmap. I am double buffering the paint. The overlayed bitmap position moves with the mouse which invalidates the Window.

这很好用,但是当背景窗口很大(想想Windows桌面)并且PC速度很慢时它太慢了.我的猜测是,每当鼠标移动时重新绘制较大的背景位图都是瓶颈.必须有一种更好,更快的方法来执行此操作,但是我的搜索没有找到我需要的答案.

This works fine except it is too slow when the background window is large (think Windows Desktop) and the PC is slow. My guess is that redrawing the large background bitmap on every mouse move is the bottleneck. There has to be a much better and faster way to do this, but my searching hasn't found the answer I need.

推荐答案

可能最快的方法是将可移动图像存储在一个位图中,然后在内存中还维护另一个具有相同大小的临时位图.要将可移动位图绘制到主图像上,首先需要使用BitBlt API函数将要绘制可移动位图的区域复制到临时位图中,然后将可移动位图BitBlt复制到主图像上.然后,当您移动可移动位图时,您将1)将临时位图BitBlt到其原始位置,然后2)将新位置BitBlt移到临时位图中,然后3)将可移动图像BitBlt移至主位图中的新位置.

Probably your fastest way would be to store your movable image in one bitmap and then maintain a second temporary bitmap of the same size in memory as well. To draw your movable bitmap over your main image, you would first use the BitBlt API function to copy the region you're about to draw the movable bitmap onto into your temporary bitmap, then BitBlt your movable bitmap onto your main image. As you move the movable bitmap then, you would 1) BitBlt the temp bitmap onto its original location, then 2) BitBlt the new location into the temp bitmap, and then 3) BitBlt the movable image onto the new location in the main bitmap.

这篇关于在C ++中快速在窗口中移动位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆