c# 截圖

 public partial class Form1 : Form
    {

        //導入 GetWindowDC函數 用於得到要截圖窗口的句柄
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public extern static IntPtr GetWindowDC(IntPtr hwnd);

        // 導入BitBlt函數 用於保存圖片到目的地
        [System.Runtime.InteropServices.DllImport("gdi32.dll")]
        public extern static UInt64 BitBlt(IntPtr hDestDC, int x, int y, int nWidth, int nHeight,
            IntPtr hSrcDC, int xSrc, int ySrc, Int32 dwRop);

//...

//截圖代碼

             Image Img = new Bitmap(this.Width, this.Height);
             Graphics g = Graphics.FromImage(Img);
             IntPtr ImageDC = g.GetHdc();

             IntPtr SourceDC = GetWindowDC(this.Handle);
             BitBlt(ImageDC, 0, 0, this.Width, this.Height, SourceDC, 0, 0, 13369376);
             g.ReleaseHdc(ImageDC);

             Img.Save("object.jpg");

<pre name="code" class="csharp">    }




發佈了35 篇原創文章 · 獲贊 8 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章