C# 截屏的问题

来源:百度知道 编辑:UC知道 时间:2024/05/24 11:02:44
首先。C#截取屏幕的代码写这
Screen scr = Screen.PrimaryScreen;
Rectangle rc = scr.Bounds;
int iWidth = rc.Width;
int iHeight = rc.Height;
Bitmap myImage = new Bitmap(iWidth, iHeight);
Graphics g1 = Graphics.FromImage(myImage);
g1.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight));

这个是截全屏。没问题。但是,随便键一个窗体。 把窗体的TransparencyKey字段设置成White。 这样,窗体背景图如果是白色的那么这白色的部分就透明了。

好,问题来了。 这样,截屏,就截不到这个窗体。为什么。 QQ的截屏工具可以截到,用键盘的PrtScr也可以截到。用这代码就是截不到。。这是为什么。希望给出解决方法。
专家,能说下原因吗?

[DllImport("gdi32.dll")]
static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int
wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, CopyPixelOperation rop);
[DllImport("user32.dll")]
static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDc);
[DllImport("gdi32.dll")]
static extern IntPtr DeleteDC(IntPtr hDc);
[DllImport("gdi32.dll")]
static extern IntPtr DeleteObject(IntPtr hDc);
[DllImport("gdi32.dll")]
static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
[DllImport("gdi32.dll")]
static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll")]
static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp);
[DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dl