Hello World

C#(WINFORM, WINCE, WINDOWS MOBILE) 실전 활용 예제소스 및 프로그램 개발

[C#]PrintWindow를 이용한 화면캡쳐 예제

댓글 0

C#

2018. 5. 18.


using System.Runtime.InteropServices;


[DllImport("user32.dll")]
static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);


private void button1_Click(object sender, EventArgs e)
{

          Graphics g = this.CreateGraphics();


          Bitmap bmp = new Bitmap(this.Width, this.Height, g);


          Graphics imgGraphics = Graphics.FromImage(bmp);

          

          IntPtr dc = imgGraphics.GetHdc();


          bool success = PrintWindow(this.Handle, dc, 0);

          

          imgGraphics.ReleaseHdc(dc);


          bmp.Save("test.bmp");


          bmp.Dispose();

}