我使用以下代码在vb.net 2010中创建了一个屏幕捕获工具:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim snappit As String = 0
TextBox1.Text -= snappit + 1
If TextBox1.Text = 0 Then
Me.Hide()
End If
If TextBox1.Text = -2 Then
Try
Dim screenshot As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim screengrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screengrab)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenshot)
screengrab.Save("snap.jpg")
MsgBox("your screen has been snapped and the snap was saved", MsgBoxStyle.Information, "ScreenShot")
Me.Show()
Timer2.Stop()
TextBox1.Text = 3
Catch ex As Exception
MsgBox("sorry unable to snap your screen and save at the moment please try again later", MsgBoxStyle.Critical, "Warning!")
End Try
End If
End Sub
此代码存储应用程序路径中的snap.jpg文件,但我想存储它 我的文档/截图
所以我用
Dim SnapDir As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Screenshot\"
是尝试将jpg文件移动到snapdir但不能成功...
那么如何在snapdir中保存jpg文件或如何使用SaveFileDialog在dir中保存该jpg文件...
由于
抱歉英语不好......
答案 0 :(得分:0)
添加了Imports System.Drawing.Imaging
将SnapDir声明为字符串
Dim SnapDir As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Screenshot"
从“\ Screenshot \”中删除尾随\。将“&”.jpg“)”添加到screengrab.Save(SnapDir)
取出一些代码,并插入命令按钮
Dim SnapDir As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Screenshot"
'Try
Dim screenshot As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim screengrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screengrab)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenshot)
MsgBox(SnapDir & "snap.jpg") 'ADDED TO SHOW DIR
screengrab.Save(SnapDir & ".jpg") 'ADDED & ".jpg")
MsgBox("your screen has been snapped and the snap was saved", MsgBoxStyle.Information, "ScreenShot")
Me.Show()
(使用此代码在Libraries \ Documents中找到的截图)