Can't Save/Overwrite Image

Findel

New member
Joined
Aug 5, 2005
Messages
2
Programming Experience
3-5
I'm trying to save and overwrite an image that has been loaded into a PictureBox and then changed. The application won't let me overwrite the original file, but it will let me save it with a different name. I think that the original file is being locked, but I am not sure how to unlock it.

here's some of my code
Private Sub openTargetFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles openTargetFile.Click
targetFileDialog.Filter = "Image Files(*.JPG)|*.JPG"
If Not targetFileDialog.ShowDialog = DialogResult.Cancel Then
targetImage = Image.FromFile(targetFileDialog.FileName)
'targetFilePath = Replace(targetFileDialog.FileName, ".jpg", "_withExif.jpg") ' this targetFilePath will save fine
targetFilePath = targetFileDialog.FileName

targetFileBox.Image = getThumb(targetImage)
End If
targetFileDialog.Dispose()
enambleCopy()
End Sub

Private Sub copyExifButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles copyExifButton.Click

Dim propItem As System.Drawing.Imaging.PropertyItem
For Each propItem In sourceImage.PropertyItems
targetImage.SetPropertyItem(propItem)
Next

targetImage.Save(targetFilePath)

feedBackMessage.Text = "Copy Complete!" & vbCrLf & "File Saved as: " & targetFilePath
feedBackMessage.Visible = True

End Sub

Any ideas why it wont save?

Any help would be great, many thanks in advance!

Findel
 
I haven't analized your code entirely but i guess you could try with

targetImage.Save(targetFilePath, True) 'the second argument is telling that overwrite is enabled

Also, try to find a thread within GDI+ forum that was recently posted there ... there is couple tricks that maybe you want to see.


Cheers ;)
 
targetImage.Save(targetFilePath, True) doesn't work. .Save doesn't take any booleans as a second parameter. The second parameter options only allow for specifying the imageType (Jpg, Gif etc.).

I'll have a look for that Thread though, thanks.
 
Back
Top