JTR
JTR

Reputation: 333

How to save images file in vb.net?

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.

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

Upvotes: 0

Views: 22293

Answers (2)

jameshwart lopez
jameshwart lopez

Reputation: 3131

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 this for more info.

Upvotes: 1

E.Solicito
E.Solicito

Reputation: 91

Try This.

Dim SaveImage As New Bitmap(PictureBox1.Image)
SaveImage.Save(SaveImagePath + SaveImageName, Imaging.ImageFormat.Jpeg)
SaveImage.Dispose()

Upvotes: 0

Related Questions