0

I am creating a LPR (License Plate Reader) in C#.

My code is based on getting an image from camera and saving it in a location, then the LPR process the image to plain text .

So every time the image taken by the cam should be replaced by new one.

But when I try to save the image for the second time, I get this error.

Here is where the problem starts.

if (pictureBox3.Image != null)
{
            Bitmap varBmp = new Bitmap(pictureBox3.Image);
            Bitmap newBitmap = new Bitmap(varBmp);
            //Save First 
            varBmp.Save(Application.StartupPath + "\\ImageTest\\1.bmp", ImageFormat.Bmp);
            //Now Dispose to free the memory
            varBmp.Dispose();
            varBmp = null;                
}
else
{
     MessageBox.Show("null exception"); 
}

I dispose the image after saving it, still instead of replacing i get this why?

I am adding more details, every time when the image is created it is processed all over by different function and events. I think those things might be holding that particular image...

Snap click http://pastebin.com/QHXkqATb

Process image http://pastebin.com/MpAVacDr

OCR (optical character Recognizer) http://pastebin.com/sXPxzQ39

Find License Plate http://pastebin.com/DH1SdebL

I have an imagebox and picture box1 which is holding these images for processing, therfore if you focus on that area you can find the error.

Any help is appreciated.

  • Please don't down vote, if you don't understand. – Account Unknown Nov 14 '15 at 05:47
  • you will get that useless-looking exception for any problem, including a simple file write error. See [“A generic error occurred in GDI+” when attempting to use Image.Save](http://stackoverflow.com/questions/14866603), then make sure you have write access to the file in question. – dbc Nov 14 '15 at 07:11
  • Was `pictureBox3.Image` previously loaded from the same file? If so see [A Generic error occured in GDI+ in Bitmap.Save method](http://stackoverflow.com/questions/15862810/a-generic-error-occured-in-gdi-in-bitmap-save-method) -- the original image will retain a lifetime lock on the file. – dbc Nov 14 '15 at 07:15

1 Answers1

1

Solved it By disposing

Imagebox1.image.dispose(); and picturebox1.image.dispose();

Thanks all for your support.