来自桌面c#的截图

时间:2017-06-20 04:50:54

标签: c# screenshot desktop

我有一个用于从桌面获取屏幕截图的c#代码

//Create a new bitmap.
            var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                           Screen.PrimaryScreen.Bounds.Height,
                                           PixelFormat.Format32bppArgb);

            // Create a graphics object from the bitmap.
            var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            // Take the screenshot from the upper left corner to the right bottom corner.
            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                                        Screen.PrimaryScreen.Bounds.Y,
                                        0,
                                        0,
                                        Screen.PrimaryScreen.Bounds.Size,
                                        CopyPixelOperation.SourceCopy);

            // Save the screenshot to the specified path that the user has chosen.
            bmpScreenshot.Save("Screenshot.png", ImageFormat.Png);

此代码工作正常,但在运行需要"管理员权限的程序时出现问题"并显示此图片:

image

上面的代码不起作用并抛出异常:"句柄无效"

我该如何解决这个问题?

0 个答案:

没有答案
相关问题