Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 3 của 3
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    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()));

  3. #3
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    hihi tự sử mới vui chứ

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •