2014-02-18 73 views
1

我在vb.net 2010使用下面的代碼創建一個屏幕捕獲工具:在應用程序的路徑如何保存JPG文件在我的文檔/ Screentshot在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但不能sucess ...

所以如何保存JPG文件snapdir或如何保存使用SaveFileDialog的dir是JPG文件...

感謝

和英語不好對不起......

+0

可能的重複[如何在vb.net中使用savefiledialog](http://stackoverflow.com/questions/15169531/h OW-DO-使用-savefiledialog式-VB網) – Plutonix

回答

0
  1. 新增進口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() 
    

(在庫\ Documents中找到此代碼的截圖)