如何在 vb.net 2010 的我的文档/屏幕截图中保存 jpg 文件
Posted
技术标签:
【中文标题】如何在 vb.net 2010 的我的文档/屏幕截图中保存 jpg 文件【英文标题】:how to save jpg file in My Document/Screentshot in vb.net 2010 【发布时间】:2014-02-18 17:01:40 【问题描述】:我在 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 但无法成功...
那么如何将 jpg 文件保存在 snapdir 或如何使用 SaveFileDialog 将 jpg 文件保存在 dir...
谢谢
抱歉英语不好...
【问题讨论】:
How do I use savefiledialog in vb.net 的可能重复项 【参考方案1】:添加了导入 System.Drawing.Imaging
将 SnapDir 声明为字符串
Dim SnapDir As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Screenshot"
从“\Screenshot\”中删除尾随 \。在screengrab.Save(SnapDir)中添加"&".jpg")"
取出一些代码,插入命令按钮
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 中使用此代码截取的屏幕截图)
【讨论】:
以上是关于如何在 vb.net 2010 的我的文档/屏幕截图中保存 jpg 文件的主要内容,如果未能解决你的问题,请参考以下文章
VB.NET 2010 和 SQL Server 2008 与 ADO.NET 问题