日期:2014-05-20  浏览次数:21034 次

提高绘图速度,使用双缓冲,告别BitBlt,以免你的内存被偷走
由于内存释放问题,使用BitBlt方法会导致内存占用慢慢长大而不会被释放,使用普通的双缓冲没有这个问题,而且速度可以
由于是裁剪了部分代码,因此存在代码不完整的问题
Cementing.CurveSplit.DrawCurvePress     再memDC指向的位图(memBmp)上画压力曲线图,其它类似


private   Graphics   memDC;             //屏幕外的图像
private   Graphics   clientDC;
private   Bitmap   memBmp;
private   static   SolidBrush   backBrush;


#region   DrawCurve   BitBlt

private   void   DrawCurveBitBlt(int   p_ScrollValue)
{
        try
        {
                if   (m_RealTime   ==   true)
                {
                        mAL   =   Cementing.PortValues.AL;     //曲线图数据来源,mAL是System.Collections.ArrayList   mAL
                }

                if   (memBmp   ==   null)                                                                                   //初始化要双缓冲的位图
                {
                        memBmp   =   null;
                        memBmp   =   new   Bitmap(m_intWidth,   m_intHeight);
                }
                else
                {
                        if   ((mWidthOld   !=   m_intWidth)   ||   (mHeightOld   !=   m_intHeight))       //位图尺寸发生了变化
                        {
                                memBmp   =   null;
                                mWidthOld   =   m_intWidth;
                                mHeightOld   =   m_intHeight;
                                memBmp   =   new   Bitmap(m_intWidth,   m_intHeight);
                        }
                }

                clientDC   =   this.CreateGraphics();       //获取绘图区的Graphics

                IntPtr   hdc   =   clientDC.GetHdc();
                IntPtr   memdc   =   Win32Support.CreateCompatibleDC(hdc);
                Win32Support.SelectObject(memdc,   memBmp.GetHbitmap());