【发布时间】:2012-10-31 05:25:37
【问题描述】:
我想通过如下代码获取DesktopWindow句柄的方式来获取特定区域。
[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(bitmap) 之类的代码,但是我无法获得我想要的图像......我的意思是,复制了 Image。 当我使用来自 Hdc 的 Graphics 对象时,我找不到获取位图图像的方法。 我必须使用DC....有什么合适的方法吗??
【问题讨论】:
标签: c# image graphics bitmap gdi