VB.NET 2012 Coding Problem (Small Demo Program Provided)
I need some help with a VB.net program I'm writing with Visual Studio 2012.
I have a piece of code that is used to browser for an image, crop the image, save the cropped image and delete the image. Sounds easy enough.
The problem is that somewhere in this process I'm not closing/releasing/disposing (you pick the right word) of something that is keeping the image file locked.
I have stripped out all the unnecessary code and made a standalone project file that can be used to demonstrate the problem and test the solution. This is a VERY simple piece of code, its just that I don't do enough work with images and bitmaps to know where the issue is.
I will provide a ZIP file of the project along with two folders of images. The first folder is for actual testing and the second folder is used to copy the files back to first folder in case you have deleted all the original files in the process of testing the solution.
Here are the steps to duplicate the issue . . .
1. Using VB.NET 2012 open the project and run it.
2. You will get a form with 5 buttons.
3. Browser for a file in the Original folder that was part of the ZIP file I included.
4. Click on Crop and draw a CROP box around a portion of the image.
5. Click on OK.
6. Save the Image (Dialog pops up saying "Image Saved")
7. Browse for a DIFFERENT picture in the ORIGINAL folder.
8. Crop this picture and save it.
9. Now go back to the first picture you cropped and try to delete it.
You should get an error at Line 120 File.Delete(sImageToCrop) saying the file was in use by another process.
There may be other ways to produce the error but basically the goal is to be able to open, crop, save and/or delete any image file at will without any issues.