如何在 vb.net 中保存图像文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33929612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to save images file in vb.net?
提问by JTR
I'm create simple paint program in vb.net, when I'm trying to save the file, the program is freeze, and I can't do anything.
我在 vb.net 中创建了简单的绘图程序,当我尝试保存文件时,程序被冻结,我无能为力。
This is my code that I'm used
这是我使用的代码
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
SaveFileDialog1.CreatePrompt = True
SaveFileDialog1.DefaultExt = "jpg"
SaveFileDialog1.Filter = "File Images (*.jpg;*.jpeg;) | *.jpg;*.jpeg; |PNG Images | *.png |GIF Images | *.GIF"
SaveFileDialog1.InitialDirectory = "F:"
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
FrmCanvas.PictureBox1.Image.Save(SaveFileDialog1.FileName)
End If
End Sub
Did I'm missed something on my code? I'm sorry, I'm new at vb.net
我在代码中遗漏了什么吗?对不起,我是 vb.net 的新手
回答by jameshwart lopez
You have missed the file format of your Image
您错过了图像的文件格式
FrmCanvas.PictureBox1.Image.Save(savefiledialog1.FileName,System.Drawing.Imaging.ImageFormat.Jpeg)
To save image on users selected format based on filter is something like this
根据过滤器以用户选择的格式保存图像是这样的
If SaveFileDialog1.FileName <> "" Then
' Saves the Image in the appropriate ImageFormat based upon the
' file type selected in the dialog box.
' NOTE that the FilterIndex property is one-based.
Select Case SaveFileDialog1.FilterIndex
Case 1
FrmCanvas.PictureBox1.Image.Save(savefiledialog1.FileName,System.Drawing.Imaging.ImageFormat.Jpeg)
Case 2
FrmCanvas.PictureBox1.Image.Save(savefiledialog1.FileName,System.Drawing.Imaging.ImageFormat.Bmp)
Case 3
FrmCanvas.PictureBox1.Image.Save(savefiledialog1.FileName,System.Drawing.Imaging.ImageFormat.Gif)
End Select
End If
Hope that helps you get the idea.
希望能帮助你理解这个想法。
Please visit thisfor more info.
请访问此了解更多信息。
回答by E.Solicito
Try This.
尝试这个。
Dim SaveImage As New Bitmap(PictureBox1.Image)
SaveImage.Save(SaveImagePath + SaveImageName, Imaging.ImageFormat.Jpeg)
SaveImage.Dispose()

