0
我想通過使用獲取像下面的代碼一樣的DesktopWindow句柄來獲取特定區域。如何使用fromHdc方法創建位圖圖像?
[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgn, uint flags);
[DllImport("user32.dll")]
static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc);
public void ScreenShot()
{
try
{
IntPtr hwnd = GetDesktopWindow();
IntPtr hdc = GetDCEx(hwnd, IntPtr.Zero, 1027);
Point temp = new Point(40, 40);
Graphics g = Graphics.FromHdc(hdc);
Bitmap bitmap = new Bitmap(mPanel.Width, mPanel.Height, g);
g.CopyFromScreen(PointToScreen(temp) , PointToScreen(PictureBox.Location) , PictureBox.Size);
}
此代碼實際工作,但我想獲得它從CopyFromScreen的工藝製作的複製圖像。我曾嘗試使用類似Graphics.FromImage(位圖)的代碼,但無法獲取我想要的圖像...我的意思是,複製圖像。 當我使用Graphics對象fromHdc時,我無法找到獲取位圖圖像的方法。 我必須使用DC ....有什麼合適的方法嗎?
謝謝您的回答雖然是有點晚gratitute(becoz林懶惰......)我的問題有已完全清除。 –
我的回答是否有幫助,或者您是以其他方式解決的? (關閉它的問題) – Arthur
(幫助吸血鬼...) – heltonbiker