我在vb.net中创建简单的绘图程序,当我试图保存文件时,程序冻结了,我什么也做不了。
这是我用过的代码
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
我是否错过了我的代码?对不起,我是vb.net的新人
答案 0 :(得分:1)
您错过了图片的文件格式
FrmCanvas.PictureBox1.Image.Save(savefiledialog1.FileName,System.Drawing.Imaging.ImageFormat.Jpeg)
要在基于过滤器的用户所选格式上保存图像,就像这样
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
希望能帮到你理解。
请访问this了解详情。
答案 1 :(得分:-1)
试试这个。
Dim SaveImage As New Bitmap(PictureBox1.Image)
SaveImage.Save(SaveImagePath + SaveImageName, Imaging.ImageFormat.Jpeg)
SaveImage.Dispose()