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()));
Với sự đa dạng và phong phú về mẫu mã và giá cả, choxeonline.vn hứa hẹn sẽ là địa chỉ tin cậy cho những ai đang tìm kiếm chiếc xe ô tô ưng ý. Từ những mẫu xe hạng sang đến những chiếc xe gia đình...
Khám Phá Đa Dạng Sản Phẩm Xe Ô Tô...