如何在vb.net 2010的My Document/Screentshot中保存jpg文件

如何在vb.net 2010的My Document/Screentshot中保存jpg文件,vb.net,jpeg,vb.net-2010,savefiledialog,Vb.net,Jpeg,Vb.net 2010,Savefiledialog,我使用以下代码在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()

我使用以下代码在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文件

谢谢

对不起,英语不好

添加了导入System.Drawing.Imaging

将SnapDir声明为字符串

Dim SnapDir As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Screenshot"
删除尾随的\从\屏幕截图\。将&jpg添加到screengrab.SaveSnapDir

取出一些代码,插入命令按钮

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中找到