当前位置: 代码迷 >> .NET Framework >> Graphics g = this.CreateGraphics();之后,怎么将转为Bitmap对象
  详细解决方案

Graphics g = this.CreateGraphics();之后,怎么将转为Bitmap对象

热度:67   发布时间:2016-05-02 00:42:51.0
Graphics g = this.CreateGraphics();之后,如何将转为Bitmap对象!
如题?

------解决方案--------------------
[System.Runtime.InteropServices.DllImport("gdi32.dll")] 
private static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop); 
 
public Bitmap GetCurrentImage() 

Graphics g = this.CreateGraphics(); 
Bitmap bitmap = new Bitmap(this.Width,this.Height,g); 
Graphics memg = Graphics.FromImage(bitmap); 
System.IntPtr dc1 = g.GetHdc(); 
System.IntPtr dc2 = memg.GetHdc(); 
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376); 
g.ReleaseHdc(dc1); 
memg.ReleaseHdc(dc2); 
memg.Dispose(); 
g.Dispose(); 
return bitmap; 

参考
  相关解决方案