using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace screenshoot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static Graphics gfxScreenshot;
private static Bitmap bmpScreenshot;
private void button1_Click(object sender, EventArgs e)
{
//最小化程式視窗
this.WindowState = FormWindowState.Minimized;
//停個一秒避免有最小化殘影
System.Threading.Thread.Sleep(1000);
//建立一個新的Bitmap
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
//從Bitmap建立一個Graphics
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
//把螢幕畫面內容複製到Graphics(Screen.PrimaryScreen表示只複製主螢幕)
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
//把畫面儲存
bmpScreenshot.Save(string.Format(@"d:\temp\{0}.jpg", DateTime.Now.Ticks.ToString()), System.Drawing.Imaging.ImageFormat.Png);
//把程式重新顯示在螢幕上
this.WindowState = FormWindowState.Normal;
}
}
}
執行畫面
只要點下儲存螢幕畫面的Button時,程式自動會縮到最小,等截完畫面後,
再回復,之後圖檔就存到D:\temp資料夾中,上述範例只有截取主要螢幕。
參考資料
http://www.dotblogs.com.tw/puma/archive/2008/08/21/4967.aspx
沒有留言:
張貼留言