C# 中的双缓冲
我在面板上绘制位图,我在同一面板上使用缩放。缩放时面板不断闪烁。为什么面板没有 DoubleBuffered 属性?
代码:
Graphics g = Graphics.FromHwnd(panel.Handle);
if (newImage == true)
{
g.Clear(SystemColors.Control);
newImage = false;
}
g.DrawImage(bmp, hOffset, vOffset);
g.Dispose();
Possible Duplicates:
How do I double buffer a Panel in C#?
c# panel for drawing graphics and scrolling
I draw a bitmap on a panel, i use zooming on the same panel. While zooming the panel is continuously flickering. Why do not panel have the DoubleBuffered property?
Code:
Graphics g = Graphics.FromHwnd(panel.Handle);
if (newImage == true)
{
g.Clear(SystemColors.Control);
newImage = false;
}
g.DrawImage(bmp, hOffset, vOffset);
g.Dispose();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在构造函数中添加此代码
Add this code inside the constructor
用这个。
我是一名游戏开发人员。在游戏中,我们首先在后缓冲区中绘制所有对象,然后将其复制或翻转到前缓冲区。您可以用作
后缓冲区并将其渲染为图形对象。
例如:
use this.
I am a game developer.In games we first draw all objects in a backbuffer and then copy or flip it to frontbuffer.You can use
as backbuffer and render it to graphics object.
for example:
你在哪里画位图?
如果不在
Paint
事件或OnPaint
重写中,那么它是错误的。为了回答您的问题,只有表单具有
DoubleBuffered
属性 IIRC。Where are you painting the bitmap?
If not in the
Paint
event orOnPaint
override, then it is wrong.To answer your question, only forms have the
DoubleBuffered
property, IIRC.我不是 100% 确定,但你不能在表单/窗口上激活 DoubleBuffered 吗?
还有一个提示,如果您要使用具有很多效果的 gui,我会使用 WPF 而不是 winforms..
您还可以覆盖 OnPaint 和 OnPaintBackground ..
Im not 100% sure but cant you activate DoubleBuffered on the form/window instead?
And one tip if your going to use gui with alot of effects i would go with WPF instead of winforms..
You can also override OnPaint and OnPaintBackground..