代码
[System.Runtime.InteropServices.DllImport(
"
gdi32.dll
"
)]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this .panel1.CreateGraphics(); // 创建的是整个panel
Size s = this .panel1.Size; // 取panel大小
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0 , 0 , this .panel1.ClientRectangle.Width, this .panel1.ClientRectangle.Height, dc1, 0 , 0 , 13369376 );
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this .panel1.CreateGraphics(); // 创建的是整个panel
Size s = this .panel1.Size; // 取panel大小
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0 , 0 , this .panel1.ClientRectangle.Width, this .panel1.ClientRectangle.Height, dc1, 0 , 0 , 13369376 );
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}