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

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; 

参考