Thread: Save problem

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Australia
    Posts
    24
    Rep Power
    0

    Save problem


    I've created this save function but it doesn't work the way that it's supposed to. First of all, whenever I bring in an image, save it and open the saved image, nothing happens, this confuses me simply because a file IS created but contains nothing. Secondly, whenever I try to save the image as a TIFF, it constsntly says that the filenemae is invalid. Can anyone help me with this problem?

    Code:
    Private Sub FileSaveAs_Click(sender As System.Object, e As System.EventArgs) Handles FileSaveAs.Click
            SaveFileDialog.AddExtension = True
            SaveFileDialog.DefaultExt = Path.GetExtension(SaveFileDialog.FileName)
            If SaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
                Try
                    Select Case SaveFileDialog.FilterIndex
                        Case 1
                            picImage.Image.Save(SaveFileDialog.FileName,System.Drawing.Imaging.ImageFormat.Bmp)
                        Case 2
                            picImage.Image.Save(SaveFileDialog.FileName,System.Drawing.Imaging.ImageFormat.Gif)
                        Case 3
                            picImage.Image.Save(SaveFileDialog.FileName,System.Drawing.Imaging.ImageFormat.Jpeg)
                        Case 4
                            picImage.Image.Save(SaveFileDialog.FileName,System.Drawing.Imaging.ImageFormat.Png)
                        Case 5
                            picImage.Image.Save(SaveFileDialog.FileName,System.Drawing.Imaging.ImageFormat.Tiff)
                    End Select
                Catch ex As Exception
                    MsgBox("There is no image to save.")
                End Try
            End If
        End Sub
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0
    I don't know if this helps, but...

    I copied your code and ran it using a picturebox with a pre-loaded image and a button to run your sub. With some debug statements in there I determined that it was only ever using the bmp format even though I was typing different extensions in the Save dialog. I added this line up near the top :

    SaveFileDialog.Filter = "BMP|*.bmp|GIF|*.gif|JPEG|*.jpeg|PNG|*.png|TIF|*.tiff"

    and then it worked as expected (with different file sizes based on the compression format used). Not sure what to tell you about the empty files, I never had that happen when I tried it.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Australia
    Posts
    24
    Rep Power
    0
    Thanks, that sorted out the TIFF problem, but the images still won't show, so I tried deleting a saved image using this process and it seems that the files aren't empty, but the images just aren't showing. So here's my code for my OpenFileDialog.
    Code:
    Private Sub FileOpen_Click(sender As System.Object, e As System.EventArgs) Handles FileOpen.Click
            OpenFileDialog.Filter = "All files(*.*)|*.*|Bitmap(*.bmp)|*.bmp|GIF(*.gif)|*.gif|JPEG(*.jpg)|*.jpg|PNG(*.png)|*.png|TIFF(*.tiff)|*.tiff"
            If OpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
                picImage.Image = image.FromFile(OpenFileDialog.FileName)
            End If
        End Sub
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0
    I'm not at my home computer right now, but I'm wondering if you just need to add a 'picImage.Refresh' line to your open file code?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Australia
    Posts
    24
    Rep Power
    0
    It works, thanks for your help

IMN logo majestic logo threadwatch logo seochat tools logo