gpt4 book ai didi

VB.NET - 对计算机上的所有屏幕进行截图

转载 作者:行者123 更新时间:2023-12-04 02:37:53 25 4
gpt4 key购买 nike

我正在 try catch 计算机上的所有屏幕,我试图摆弄 Screen.AllScreens 以及一些我不记得的 VirtualScreens ,所以我转到 PrimaryScreen 以确保其他一切正常。

这是我现在的类(class):

Public Class wmCapture

Public Shared Function screenCapture()
Dim userName As String = Environment.UserName
Dim savePath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Dim dateString As String = Date.Now.ToString("yyyyMMddHHmmss")
Dim captureSavePath As String = String.Format("{0}\WM\{1}\capture_{2}.png", savePath, userName, dateString)
Dim bmp As Bitmap = New Bitmap( _
Screen.PrimaryScreen.Bounds.Width, _
Screen.PrimaryScreen.Bounds.Height)

Dim gfx As Graphics = Graphics.FromImage(bmp)

gfx.CopyFromScreen( _
Screen.PrimaryScreen.Bounds.Location, _
New Point(0, 0), Screen.PrimaryScreen.Bounds.Size)

bmp.Save(captureSavePath)

End Function

End Class

我应该在 Screen 命名空间中使用什么来包含所有事件屏幕?

最佳答案

你很接近。我进行了一些调整,可以确认它对我有效。

Public Shared Sub screenCapture()
Dim userName As String = Environment.UserName
Dim savePath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Dim dateString As String = Date.Now.ToString("yyyyMMddHHmmss")
Dim captureSavePath As String = String.Format("{0}\WM\{1}\capture_{2}.png", savePath, userName, dateString)
' This line is modified for multiple screens, also takes into account different screen size (if any)
Dim bmp As Bitmap = New Bitmap( _
Screen.AllScreens.Sum(Function(s As Screen) s.Bounds.Width),
Screen.AllScreens.Max(Function(s As Screen) s.Bounds.Height))
Dim gfx As Graphics = Graphics.FromImage(bmp)
' This line is modified to take everything based on the size of the bitmap
gfx.CopyFromScreen(SystemInformation.VirtualScreen.X,
SystemInformation.VirtualScreen.Y,
0, 0, SystemInformation.VirtualScreen.Size)
' Oh, create the directory if it doesn't exist
Directory.CreateDirectory(Path.GetDirectoryName(captureSavePath))
bmp.Save(captureSavePath)
End Sub

关于VB.NET - 对计算机上的所有屏幕进行截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20504433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com