Window Mobile中Panel上绘图的闪烁消除方法

来源:互联网 发布:快3遗漏数据分析 编辑:程序博客网 时间:2024/05/18 19:42

在PC上利用做开发时,通常利用双缓冲技术来去除绘图时发生的闪烁问题。但在Windows Mobile的开发中,Form本身去掉了DoubleBuffered属性,而利用双缓冲问题也往往不能得到很好的去除闪烁的效果。

日前在http://dev.10086.cn/cmdn/wiki/index.php?doc-view-2214.html看到了下述方法,非常有效的解决了在Panel上绘图的闪烁问题。

//PaintPanel.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace Test

{
    class PaintPanel: System.Windows.Forms.Panel
    {
        protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
        {
            //不重绘背景
        }
    }
}

然后用PaintPanel代替原来的Panel,并在Panel的Paint函数中使用双缓冲方式绘图,即:

Bitmap  bmp = new Bitmap(width, height);

Graphic gBmp = Graphics.FromImage(bmp);

gBmp.DrawXXX(………..

g.DrawImage(…..

bmp.Dispose();

 

但由于Bitmap每次分配会消耗较多的时间,对于需要实时(或准实时)显示的应用,最好定义一个全局的Bitmap对象用来做绘图,能提高不少效率。

原创粉丝点击