首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET Framework >

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

2012-03-20 
Graphics g this.CreateGraphics()之后,如何将转为Bitmap对象!如题?[解决办法][System.Runtime.Interop

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; 

参考

热点排行