Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

I'm writing a program that gets the path to an image and sets it to an image variable:

 

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

 

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

 

And, finally the problem occurs:

 

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:

Posted

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:

 

CurrentImage.Dispose

Or something like:

CurrentImage = Nothing

 

Before you kill the file.

"Reality is fake, Dreams are for real"
Posted

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 I'm sure VB.NET uses the file while it is resizing it, but it won't give up control of the file even after both

 

Image = Nothing

and

Image.dispose()

 

are run...

 

Any suggestions???

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...