WinCE 4.2(.net精简框架集)下的图形双缓存处理
2008-03-11 15:31
309 查看
在上位机Windows操作平台( .net 2.0框架集)下实现图形双缓存有很多办法,每种办法在上位机都有很好的效果,但是很不幸,在WinCE4.2操作系统(.net 2.0精简框架集)下这些方法要么不支持,要么效果很差(还是闪烁的厉害)。
在上位机中,一般都有这么几种办法:
1、应用程序中使用双缓冲的最简便的方法是使用 .NET Framework 为窗体和控件提供的默认双缓冲,通过将 DoubleBuffered 属性设置为True即可。
2、通过SetStyle修改控件属性。
public void EnableDoubleBuffering()
{
// Set the value of the double-buffering style bits to true.
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
}
3、比较经典的一种如下:重载OnPaint函数
protected override void OnPaint(PaintEventArgs e)
{
System.Drawing.Bitmap b = new Bitmap(this.Width,this.Height);//双缓冲技术,先将所有要画的画在该图片中,再调用GS画出该图片.
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
//在这里画你所需要画的 //-------------------
e.Graphics.DrawImage((System.Drawing.Image)b,0,0);
g.Dispose(); base.OnPaint (e);
} 前两种办法在WinCE下都不支持,第三种办法是可以使用的,但效果不佳,还是有明显的闪烁现象。经过上网查资料和测试,发现在第三种办法基础上要进行如下处理,效果才非常完美。 由于我是在Panel上绘的图,所以我派生了一个类EmbedPanel,重载了OnPaintBackground函数,并且置该函数为空。
public class EmbedPanel : Panel
{
protected override void OnPaintBackground(PaintEventArgs paintg)
{
//不绘制背景
}
} private void pb_Paint(object sender, PaintEventArgs e)
{
try
{
pb_Graphics.FillRectangle(new SolidBrush(BackColor), Rect); //绘制背景
//-------------------------------------------------------- ... ... 具体的绘图代码 //--------------------------------------------------------
e.Graphics.DrawImage((System.Drawing.Image)pb_Bitmap, 0, 0);
}
catch (Exception err)
{
ShowInfo(3000, 2, err.Message, "pb_Paint");
}
} //注:在WINCE测试时发现,在OnPaint中的写System.Drawing.Bitmap b = new Bitmap(this.Width,this.Height)代码,程序运行不长时间便会导致WinCE死机。所以我是在类的初始化中执行该代码的。 这样一来,就很完美的在.net精简框架集下解决了绘图闪烁问题。
在上位机中,一般都有这么几种办法:
1、应用程序中使用双缓冲的最简便的方法是使用 .NET Framework 为窗体和控件提供的默认双缓冲,通过将 DoubleBuffered 属性设置为True即可。
2、通过SetStyle修改控件属性。
public void EnableDoubleBuffering()
{
// Set the value of the double-buffering style bits to true.
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
}
3、比较经典的一种如下:重载OnPaint函数
protected override void OnPaint(PaintEventArgs e)
{
System.Drawing.Bitmap b = new Bitmap(this.Width,this.Height);//双缓冲技术,先将所有要画的画在该图片中,再调用GS画出该图片.
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
//在这里画你所需要画的 //-------------------
e.Graphics.DrawImage((System.Drawing.Image)b,0,0);
g.Dispose(); base.OnPaint (e);
} 前两种办法在WinCE下都不支持,第三种办法是可以使用的,但效果不佳,还是有明显的闪烁现象。经过上网查资料和测试,发现在第三种办法基础上要进行如下处理,效果才非常完美。 由于我是在Panel上绘的图,所以我派生了一个类EmbedPanel,重载了OnPaintBackground函数,并且置该函数为空。
public class EmbedPanel : Panel
{
protected override void OnPaintBackground(PaintEventArgs paintg)
{
//不绘制背景
}
} private void pb_Paint(object sender, PaintEventArgs e)
{
try
{
pb_Graphics.FillRectangle(new SolidBrush(BackColor), Rect); //绘制背景
//-------------------------------------------------------- ... ... 具体的绘图代码 //--------------------------------------------------------
e.Graphics.DrawImage((System.Drawing.Image)pb_Bitmap, 0, 0);
}
catch (Exception err)
{
ShowInfo(3000, 2, err.Message, "pb_Paint");
}
} //注:在WINCE测试时发现,在OnPaint中的写System.Drawing.Bitmap b = new Bitmap(this.Width,this.Height)代码,程序运行不长时间便会导致WinCE死机。所以我是在类的初始化中执行该代码的。 这样一来,就很完美的在.net精简框架集下解决了绘图闪烁问题。
相关文章推荐
- WinCE 4.2(.net精简框架集)下的图形双缓存处理
- WinCE 4.2(.net精简框架集)下的图形双缓存处理
- WinCE 4.2(.net精简框架集)下的图形双缓存处理
- 玩转Android---2D图形及动画---图片处理
- [Winform]缓存处理
- C# JS 自定义控件 缓存处理
- 图形图像处理-之-误差扩散 上篇
- 55、Android网络图片 加载缓存处理库的使用
- 网络加载图片及图片缓存处理
- 图形图像处理-之-高质量的快速的图像缩放 补充 使用SSE2优化
- windows下Python 3.x图形图像处理库PIL的安装
- Android Http缓存数据处理
- wince6.0 过期处理
- 高密度图形处理
- 使用委托进行高级ASP.NET缓存处理
- java 图像处理截圆形的图形(修改版)
- ajax请求在ie下缓存的处理
- [转载]浅谈Google Skia图形处理引擎
- 4.2 设计具有背景图的按钮---ImageButton的焦点以及事件的处理
- 串口通信中接收数据时延迟处理与缓存处理的解决方案(C#)