Image resizing in


I have some code for resizing an image. The function returns a bitmap object based on the original image of the new size. I would like to be able to save the bitmap with the same name as the original file that I resized to overwrite it but i get an error when i call presumably because the filename is already in use. How do i get around this?
Do i have to delete the orginal file before i save the new bitmap or is there a way to overwrite the existing file.


Who is Participating?
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can use code like this to release the file lock on the image:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fileName As String = "c:\someImage.jpg"

        Dim tempImg As Image = Image.FromFile(fileName)
        Dim bmp As New Bitmap(tempImg)

        tempImg.Dispose() ' releases the file lock on "fileName"

        ' do something with "bmp"...

    End Sub
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.