tạo ra 1 class Capture.cs
Mã:
public class Capturer
{
[DllImport("coredll.dll")]
public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
[DllImport("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hwnd);
const int SRCCOPY = 0x00CC0020;
public static Bitmap Snapshot(Rectangle rectangle, IntPtr wnd)
{
try
{
IntPtr deviceContext = wnd;
Bitmap capture = new Bitmap(rectangle.Width, rectangle.Height);
Graphics deviceGraphics = Graphics.FromHdc(deviceContext);
Graphics captureGraphics = Graphics.FromImage(capture);
BitBlt(captureGraphics.GetHdc(), 0, 0, rectangle.Width, rectangle.Height, deviceGraphics.GetHdc(), rectangle.Left, rectangle.Top, SRCCOPY);
captureGraphics.Dispose();
return capture;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}
}
}
form sử dụng
Mã:
Craphics g1 = this.CreateGraphics();
Images img = new Bitmap(Capturer.Snapshot(new Rectangle(0, 0, this.Width, this.Height), g1.GetHdc()));
Pallet nhựa Lâm Đồng giải pháp hoàn hảo cho nhà kho Pallet nhựa Lâm Đồng là một giải pháp đa năng và hiệu quả trong việc vận chuyển và lưu trữ hàng hóa. Trong đó, pallet nhựa Lâm Đồng không chỉ đáp...
Pallet nhựa Lâm Đồng giải pháp...