0

I have a colored TIF image in a PictureBox. To convert it to grayscale I need to: (1) free the image from the pictureBox. (2) move the image from the working folder to a temp folder (3)use the grayscale subroutine to convert from color in the temp folder to gray in the working folder.
My problem is that Visual Basic will not release the image in the PictureBox so that I can move it.

Dim fileLeft As String
Dim fileCopy As String

Me.PicBoxLeft.Image = Nothing
{{ free up the image now }}
fileLeft = TNpath + "\" + fileNames(q)
fileCopy = "C:\AuditBook\Temp\" + fileNames(q)
My.Computer.FileSystem.MoveFile(fileLeft, fileCopy, True)

How do I get Visual Basic to free up the image?

JerrMerr
  • 11
  • 4
  • Did you by chance load that image using [FromFile](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.image.fromfile?view=windowsdesktop-5.0)? "The file remains locked until the Image is disposed." If so, load it up using an alternative method. – Idle_Mind Nov 13 '21 at 01:46
  • Yes it was loaded using FromFile. ************************************ imgLeft = Image.FromFile(fileLeft) ' Image to display image Me.PicBoxLeft.Image = imgLeft ************************************ How do you "dispose" of the image? What other way(s) can be used to load the image? Could I just load an image that looks like the PictureBox background? – JerrMerr Nov 14 '21 at 02:10
  • See [here](https://stackoverflow.com/a/19749124/2330053) for one method. – Idle_Mind Nov 14 '21 at 04:57

0 Answers0