C#做出 Print Screen 儲存螢幕畫面的功能(截圖)

C#做出 Print Screen 儲存螢幕畫面的功能(截圖)

C#做出 Print Screen 儲存螢幕畫面的功能(截圖)


資料來源: https://dotblogs.com.tw/chou/2009/03/08/7410


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 

namespace PrintScreen 
{ 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
        } 

        private void button1_Click(object sender, EventArgs e) 
        { 
            Bitmap myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); 
            Graphics g = Graphics.FromImage(myImage); 
            g.CopyFromScreen(new Point(0,0), new Point(0, 0), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)); 
            IntPtr dc1 = g.GetHdc(); 
            g.ReleaseHdc(dc1); 
            myImage.Save("screen0.jpg"); 
        } 

        private void button2_Click(object sender, EventArgs e) 
        { 
            Bitmap myImage = new Bitmap(this.Width, this.Height); 
            Graphics g = Graphics.FromImage(myImage); 
            g.CopyFromScreen(new Point(this.Location.X, this.Location.Y), new Point(0, 0), new Size(this.Width, this.Height)); 
            IntPtr dc1 = g.GetHdc(); 
            g.ReleaseHdc(dc1); 
            myImage.Save("screen1.jpg"); 
        } 
    } 
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *