我应该使用 .NET 的内置双缓冲还是我自己的实现?

发布于 2024-09-06 08:50:22 字数 752 浏览 3 评论 0原文

我正在 Visual C++ 中进行一些 GDI+ 绘图,并注意到我的画布在滚动、调整大小等时看起来不是最好的...由于大量闪烁和缓慢的重绘。根据我的阅读,解决方案是双缓冲,但对于如何实现存在相互矛盾的建议。

一些消息来源建议使用现有的 .NET 实现,如下所示:

using namespace System::Windows::Forms;  
this->SetStyle(ControlStyles::AllPaintingInWmPaint |  
               ControlStyles::UserPaint |  
               ControlStyles::DoubleBuffer, true);

更多消息来源建议只绘制到您自己的位图,然后将其扔到屏幕上:

dbBitmap = gcnew Bitman(ClientRectangle.Width, ClientRectangle.Height);
dbGraphics = Graphics::FromImage(dbBitmap);

// use the graphics object to do everything you need to here

this->createGraphics()->DrawImageUnscaled(dbBitmap, 0, 0);

这些方法之间是否存在功能差异,或者我只是将最前沿微软在后台做了什么?我担心速度和效率,以及使用一种方法而不是另一种方法可能存在的陷阱。

I am doing some GDI+ drawing in Visual C++ and noticed that my canvas doesn't look the best when scrolling, resizing, etc... due to lots of flickering and slow redraws. From what I've read, the solution is to double buffer but there are conflicting suggestions on how to implement.

A few sources suggest to use the existing .NET implementation, like so:

using namespace System::Windows::Forms;  
this->SetStyle(ControlStyles::AllPaintingInWmPaint |  
               ControlStyles::UserPaint |  
               ControlStyles::DoubleBuffer, true);

Many more sources recommend just drawing to your own bitmap and then throwing it onto the screen:

dbBitmap = gcnew Bitman(ClientRectangle.Width, ClientRectangle.Height);
dbGraphics = Graphics::FromImage(dbBitmap);

// use the graphics object to do everything you need to here

this->createGraphics()->DrawImageUnscaled(dbBitmap, 0, 0);

Is there a functional difference between these approaches, or would I just be bringing to the forefront what Microsoft does in the background? I'm concerned about both speed and efficiency, as well as possible pitfalls of using one approach over the other.

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

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

发布评论

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

评论(1

梦里南柯 2024-09-13 08:50:22

只需在构造函数或“属性”窗口中将表单的 DoubleBuffered 属性设置为 true 即可。您必须在 Paint 事件中进行绘制,使用 CreateGraphics() 永远是不正确的。如果发生需要重新绘制窗口的情况,请调用 Invalidate() 或 Update()。

Just set the form's DoubleBuffered property to true in the constructor or the Properties window. You have to draw in the Paint event, using CreateGraphics() is never correct. Call Invalidate() or Update() if something happens that would require the window to be repainted.

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