Image resizing in

Posted on 2006-05-27
Last Modified: 2010-04-23

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.


Question by:andieje
    1 Comment
    LVL 85

    Accepted Solution

    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

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video discusses moving either the default database or any database to a new volume.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now