Re: [問題] process handle
以下是我的截圖部分,目標是讀取ArrayList path裡的各個資料夾路徑
動作是資料夾開啟->資料夾截圖->儲存圖片->關閉資料夾
截圖的程式碼是參考http://ppt.cc/j;fc的指定窗口截圖的部分
不曉得是哪裡有錯誤,圖一直儲存不出來
且在輸出視窗中會出現:'System.InvalidOperationException'發生於System.dll
或者不曉得有沒有更好或簡便的截圖方法,懇請指點迷津
public bool pic(ArrayList path)
{
foreach (string i in path)
{
ProcessStartInfo startInfo = new
ProcessStartInfo("explorer.exe");
startInfo.Arguments = i;
Process p = Process.Start(startInfo);
Image img = CaptureWindow(p.Handle);
img.Save(string.Format(@"c:\{0}.jpg",
DateTime.Now.Ticks.ToString()),
System.Drawing.Imaging.ImageFormat.Jpeg);
p.close();
}
return true;
}
public Image CaptureWindow(IntPtr handle)
{
IntPtr hdcSrc = User32.GetWindowDC(handle);
User32.RECT windowRect = new User32.RECT();
User32.GetWindowRect(handle, ref windowRect);
int width = windowRect.right - windowRect.left;
int height = windowRect.bottom - windowRect.top;
IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width,height);
IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);
GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0,GDI32.SRCCOPY);
GDI32.SelectObject(hdcDest, hOld);
GDI32.DeleteDC(hdcDest);
User32.ReleaseDC(handle, hdcSrc);
Image img = Image.FromHbitmap(hBitmap);
GDI32.DeleteObject(hBitmap);
return img;
}
※ 編輯: coldwind7810 來自: 118.167.182.239 (12/09 01:25)
→
12/09 07:53, , 1F
12/09 07:53, 1F
感謝樓上大大的回答,沒有注意到,現在終於可以截了,但畫面還是截不到開啟的資料夾
有時候是空的,有時候會截到其他我開啟的程式的控制項
※ 編輯: coldwind7810 來自: 118.167.174.73 (12/09 20:10)
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章