• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Image resizing in vb.net

Hi

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 bitmap.save 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.

Thanks
andrea

           
0
andieje
Asked:
andieje
1 Solution
 
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"...

        bmp.Save(fileName)
    End Sub
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now