如何将图片从图片库保存为jpg
问题描述:
我已经能够将文件保存为.jpeg,但图片无法加载,有没有人有建议?如何将图片从图片库保存为jpg
Private Sub Btnconfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnconfirm.Click
MsgBox("A receipt will now be saved to your files", vbOKOnly, "Thank you for your purchase")
SaveFileDialog1.ShowDialog()
MsgBox("Thank you for choosing Tiny Theatre, have a nice day.", vbOKOnly, "Thank you")
Me.Close()
End Sub
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
Dim FileToSaveAs As String = SaveFileDialog1.FileName
Dim objwriter As New System.IO.StreamWriter(FileToSaveAs)
objwriter.Write(PictureBox1)
objwriter.Close()
End Sub
答
没有尝试过,但可能这样做吗?
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
Dim FileToSaveAs As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, SaveFileDialog1.FileName)
PictureBox1.Image.Save(FileToSaveAs, System.Drawing.Imaging.ImageFormat.Jpeg)
End Sub
如果您需要设置编码器参数(如JPEG压缩),你将需要保存方法的重载。请参阅http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.image.aspx和http://msdn.microsoft.com/en-us/library/system.drawing.image.aspx
提供的代码将序列化格式的图片框控件保存为具有扩展名为jpeg的文件。将text.txt文件重命名为text.jpg不会使其成为有效的jpg图像。这是一样的。
答
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
Dim FileToSaveAs As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, SaveFileDialog1.FileName)
PictureBox1.Image.Save(FileToSaveAs, System.Drawing.Imaging.ImageFormat.Jpeg)
End Sub
图像保存后,它出现在我保存它的任何地方(像它应该),但图像不会打开,我做错了什么? – Boats 2013-05-10 18:59:42
“PictureBox1”是什么类型的控件?您是否在十六进制编辑器中查看生成的文件的内容?如果您将扩展名更改为其他内容,例如'.png','.gif','.bmp'等,图像是否会打开? – 2013-05-10 19:06:07
对不起,我不确定你的意思 – Boats 2013-05-10 19:12:24