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

时间:2014-02-18 17:01:41

标签: 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()
    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文件...

由于

抱歉英语不好......

1 个答案:

答案 0 :(得分:0)

  1. 添加了Imports System.Drawing.Imaging

  2. 将SnapDir声明为字符串

    Dim SnapDir As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Screenshot"
    
  3. 从“\ Screenshot \”中删除尾随\。将“&”.jpg“)”添加到screengrab.Save(SnapDir)

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

    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()
    
  5. (使用此代码在Libraries \ Documents中找到的截图)