/* 目標視窗必須顯示在最上層
* 引入 Win32 API 中的 User32.DLL
* 需要加上 using System.Runtime.InteropServices;
*/
[DllImport("user32.dll")]
public static extern Boolean GetWindowRect(IntPtr hWnd, ref Rectangle bounds);
public void CaptureWindow () {
/* 取得目標視窗的 Handle
* 需要加上 using System.Diagnostics;
*/
Process[] process = Process.GetProcessesByName("notepad");
/* 取得該視窗的大小與位置 */
Rectangle bounds;
GetWindowRect(process[0].MainWindowHandle, ref bounds);
/* 抓取截圖 */
Bitmap screenshot = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
Graphics gfx = Graphics.FromImage(screenshot);
gfx.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
/* 利用 PictureBox 顯示出來 */
imageView.Image = (Image) screenshot;
imageView.Update();
}
2011年7月4日 星期一
視窗截圖
在文字的世界裡尋找心靈的共鳴,遠山藍以溫柔的筆觸分享書籍的力量與生活的智慧。無論是細膩的書評、深刻的人生感悟,還是技術與創新的新奇發現,每篇文章都是一次內心的療癒旅程。希望透過閱讀,帶領讀者在忙碌的生活中找到一片寧靜與啟發。讓我們一起,在書香中遇見更好的自己!
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言