Graphics.CopyFromScreen 创建空白图像
我正在使用 VB.NET 尝试捕获屏幕的一部分,因此我在几个地方找到了这段代码来捕获整个屏幕:
Dim screenSize = SystemInformation.PrimaryMonitorSize
Dim bitmap = New Bitmap(screenSize.Width, screenSize.Height)
Using g As Graphics = Graphics.FromImage(bitmap)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenSize)
End Using
bitmap.Save("c:\scratch\screenshot.png", System.Drawing.Imaging.ImageFormat.Png)
这可以正常工作,不会抛出错误,并且文件已成功创建,但生成的图像是完全透明的(它尺寸正确)-我缺少什么?
这个问题涉及相同的错误,但解决方案是使用Win32如果可能的话我想避免使用GDI
I am using VB.NET to try and capture a portion of the screen so I found this code in several places to capture the whole screen:
Dim screenSize = SystemInformation.PrimaryMonitorSize
Dim bitmap = New Bitmap(screenSize.Width, screenSize.Height)
Using g As Graphics = Graphics.FromImage(bitmap)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenSize)
End Using
bitmap.Save("c:\scratch\screenshot.png", System.Drawing.Imaging.ImageFormat.Png)
This works with no error throw and the file is created successfully but the resulting image is completely transparent (it is the correct size) - what am I missing?
This question relates to the same error but the solution is to use Win32 GDI which I want to avoid if possible
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 CopyFromScreen 方法存在问题,我最终决定采用打印屏幕选项:
I decided to go along the print screen option in the end due to the issues with the CopyFromScreen method: