I am converting an TIFF file to a .PNG file in vb.net. First, I save the TIFF file to a specific location (given by NewFileName). Then I convert the file to .PNG using the Bitmap.Save method. Later in my program, I attempt to delete all the .tif files. However, I get an error that says the files are still in use. I have done some research about the reasons for this and I have read that a lot of the errors come from not closing filestream. However, I do not use filestream in my program so I think it is something else. Another possibility that was suggested was that the file was opened twice. I have scoured my code and I am pretty sure the files were never opened, only saved and accessed with the bitmap.Save
command. I also downloaded handle.exe
and process explorer to find which process was locking the files. Apparently, the files are only in use by the program once I convert them to PNG using the bitmap.save
command. Maybe there is a way to close bitmap.Save
? Any other suggestions of what to add would be appreciated as well.
objApplication.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyViewBottomView)
view = window.View
view.Fit()
withoutExt = "C:\Folder" & "\" & shortForms(12) & FileName
NewFileName = withoutExt & ".tif"
view.SaveAsImage(NewFileName, Width:=width, Height:=height, Resolution:=resolution, ColorDepth:=colorDepth)
System.Drawing.Bitmap.FromFile(NewFileName).Save(withoutExt & ".png", System.Drawing.Imaging.ImageFormat.Png)
Thanks in advance!