CDC MemDC;                                      //首先定义一个显示设备对象
      CBitmap MemBitmap;                              //定义一个位图对象
                                     
      MemDC.CreateCompatibleDC(NULL);          //随后建立与屏幕显示兼容的内存显示设备
      MemBitmap.CreateCompatibleBitmap(pDC,nWidth,nHeight);
      
      CBitmap *pOldBit=MemDC.SelectObject(&MemBitmap);//将位图选入到内存显示设备中
      //只有选入了位图的内存显示设备才有地方绘图,画到指定的位图上
      //先用背景色将位图清除干净,这里我用的是白色作为背景
      //你也可以用自己应该用的颜色
      MemDC.FillSolidRect(0,0,nWidth,nHeight,RGB(255,255,255));
      //绘图
      MemDC.MoveTo(……);
      MemDC.LineTo(……);
      //将内存中的图拷贝到屏幕上进行显示
      pDC->BitBlt(0,0,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
      //绘图完成后的清理
      MemBitmap.DeleteObject();
      MemDC.DeleteDC();
      CDC MemDC 类型在C#中对应什么类型?

解决方案 »

  1.   

    System.Drawing 命名空间是对 GDI 的包装,楼主如果熟悉 GDI 的话一看就应该明白。我不熟悉,GDI 一听头都大了。:)
      

  2.   

    CDC MemDC 类型在C#中对应什么类型?
      

  3.   

    谢谢,那我如何把图像写到内存?内存我该用什么类型表示,我想用bitBlt这个函数,把图像先写到内存,然后由内存再写到窗口,这样就实现了双重缓冲,避免了窗口的闪烁现象,还有就是大家都知道的用
    this.SetStyle(ControlStyles.DoubleBuffer,true);
    this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
    this.SetStyle(ControlStyles.UserPaint,true);
    this.UpdateStyles();
    实现双重缓冲,在实际应用中根本就不好用,一点作用都没有,窗口该还闪烁。
      

  4.   

    还有.net2005我也试了,虽说每个winform窗体都有DoubleBuffered属性,对窗口的闪烁来说,也是一点作用也没有。
      

  5.   

    Bitmap m_bmpOffscreen=null;
    Image imageFile = Image.FromFile(@"E:\TouchMan\TouchMan\bin\Debug\resources\images\BKG_1.JPG");
    protected override void OnPaint(PaintEventArgs e)
    {

    Graphics gxOff; //屏幕外的图像 if (m_bmpOffscreen == null) //要双缓冲的位图
    {
    m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);
    }
                Rectangle rc = this.ClientRectangle; gxOff = Graphics.FromImage(m_bmpOffscreen);
    gxOff.Clear(this.BackColor);
    //imageFile.
    //绘制一些位图
    gxOff.DrawImage(imageFile, 0, 0, rc, GraphicsUnit.Pixel);
       
    //边界矩形

    // rc.Width--;
    // rc.Height--;
                
    //绘制边界
    //gxOff.DrawRectangle(new Pen(Color.Black), rc);
    //从内存位图绘制
    e.Graphics.DrawImage(m_bmpOffscreen, 0, 0,rc,GraphicsUnit.Pixel); base.OnPaint( e ); //this.FromImageImage(e);
    // base.OnPaint( e );

    }
    Bitmap m_bmpOffscreen=null;
    Image imageFile = Image.FromFile(@"E:\TouchMan\TouchMan\bin\Debug\resources\images\BKG_1.JPG");
    protected override void OnPaint(PaintEventArgs e)
    {

    Graphics gxOff; //屏幕外的图像 if (m_bmpOffscreen == null) //要双缓冲的位图
    {
    m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);
    }
                Rectangle rc = this.ClientRectangle; gxOff = Graphics.FromImage(m_bmpOffscreen);
    gxOff.Clear(this.BackColor);
    //imageFile.
    //绘制一些位图
    gxOff.DrawImage(imageFile, 0, 0, rc, GraphicsUnit.Pixel);
       
    //边界矩形

    // rc.Width--;
    // rc.Height--;
                
    //绘制边界
    //gxOff.DrawRectangle(new Pen(Color.Black), rc);
    //从内存位图绘制
    e.Graphics.DrawImage(m_bmpOffscreen, 0, 0,rc,GraphicsUnit.Pixel); base.OnPaint( e ); //this.FromImageImage(e);
    // base.OnPaint( e );

    }
    Bitmap m_bmpOffscreen=null;
    Image imageFile = Image.FromFile(@"E:\TouchMan\TouchMan\bin\Debug\resources\images\BKG_1.JPG");
    protected override void OnPaint(PaintEventArgs e)
    {

    Graphics gxOff; //屏幕外的图像 if (m_bmpOffscreen == null) //要双缓冲的位图
    {
    m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);
    }
                Rectangle rc = this.ClientRectangle; gxOff = Graphics.FromImage(m_bmpOffscreen);
    gxOff.Clear(this.BackColor);
    //imageFile.
    //绘制一些位图
    gxOff.DrawImage(imageFile, 0, 0, rc, GraphicsUnit.Pixel);
       
    //边界矩形

    // rc.Width--;
    // rc.Height--;
                
    //绘制边界
    //gxOff.DrawRectangle(new Pen(Color.Black), rc);
    //从内存位图绘制
    e.Graphics.DrawImage(m_bmpOffscreen, 0, 0,rc,GraphicsUnit.Pixel); base.OnPaint( e ); //this.FromImageImage(e);
    // base.OnPaint( e );

    }
     上面的方法也不行