Program Won't let Me Delete Image after Editing

Audax321

Well-known member
Joined
May 4, 2002
Messages
90
Hello,

Im writing a program that gets the path to an image and sets it to an image variable:

Code:
Dim file as String
Dim CurrentImage as Image

file = "C:\wallpaper.bmp"
CurrentImage = Image.FromFile(file)

Then, I resize the picture and save it as another filename...

Code:
CurrentImage = CurrentImage.GetThumbnailImage(NewSize.Width, NewSize.Height, Nothing, Nothing)
CurrentImage.Save(NewPath & "\" & "newname.bmp")

And, finally the problem occurs:

Code:
Kill(file)

The program will not let me delete the original file because it is being used by another process (which is my program). I found out it was my program because if I delete the image before any of the above code runs, the file is deleted fine.

How can I do this in a way that will let me delete the file???? :confused:
 
perhaps after saving the file is still being of use. I would create a timer, wait a few seconds, and then go with the killing of the file.

-----------

Actually the image is still in the variable CurrentImage, so try going like this if it is available to the CurrentImage variable:

[VB]
CurrentImage.Dispose
[/VB]
Or something like:
[VB]
CurrentImage = Nothing
[/VB]

Before you kill the file.
 
I ran into another problem. When I tested my application in the previous post, I accidentally left out the resize feature. If I put the image resizing back in, which is done by using GetThumbNail on the Image variable, it again does not allow me to delete the original file. This is understandable because Im sure VB.NET uses the file while it is resizing it, but it wont give up control of the file even after both

Image = Nothing
and
Image.dispose()

are run...

Any suggestions???
 
Back
Top