Hello I have a problem and not sure how to fix it.
I've created an inventory application using C#.net
A user is able to pull up a part with info and with a picture of that part.
I load the picture into a picturebox using the code....
Image ing = Image.FromFile(FILELOCATION);
PICTUREBOX.Image = ing;
works great.
The problem is when the user clicks SAVE to save it all back it won't do it.
I get an error that says "A GENERIC ERROR OCCURRED IN GDI+"
I understand what it means... it means that I can't right back to that folder that has the loaded image. The image is locked. How do I unlock the image(picture) once I loaded into my application(picture-box).
Please help. Code same would be great.
thank you so so much

3 answers
use
to free up the resources
answered 8 months ago by:
1822
15
Hello Foamy. I tried using ing.Dispose() but I get an error msg that says 'Invalid parameter used" Any other suggestions.
1822
Post the code and let's have a look :)
15
strimage = (ds.Tables["Inventory"].Rows[0]["Image1"]).ToString(); txtImageName.Text = strimage; Image ing = Image.FromFile(@"C:\Documents and Settings\Joe\My Documents\My Pictures\"+strimage+" "); pbpart.Image = ing; ing.Dispose(); Let me explain how this works...... I keep the name of the pictures in an access database. The names are kept in a table called Image1. When the user goes into the application and looks up a part it checks the table for the name of the part and then it goes into a folder that holds the pictures and it pulls it up.... that works great... but now if the user changes the picture of some other information and clicks on save it won't... cause the code has the picture locked... As of now I'm just testing the code... so I'm the only one accessing the program. I'm running as admin so I don't think it has anything to do with the permission of the folder. Please help
15
additional note: pbpart is the name of my picturebox
1822
You shouldn't call Dispose until you're done with the image :) This means you will need to keep a reference to it in your class and call Dispose when the user clicks 'save'
15
Still not working... I place... pbpart.Image.Dispose(); in the "Save" button code.... right before the line of code... pbpart.Image.Save("C:\\Documents and Settings\\Joe\\My Documents\\My Pictures\\"+txtImageName.Text+" ", ImageFormat.Jpeg); Still getting the same error msg. Other suggestions, please????
1699
after you create the image, create a second instance using img.Clone (you'll have to cast it back to an image), because it loads and locks the original file when you load the image from file. open the image, clone it, dispose of it, use the cloned image to assign to the picture box, then use that one to save.
15
Hello MadHatter, I understand what you are saying. I'm just not sure how to write this code. Can you please help me out. thank you
15
Can some please help me out with the code. How does Clone() work ????????? PLEASE
Image image = Image.FromFile(@"C:\Documents and Settings\Joe\My Documents\My Pictures\"+strimage+" ");
Bitmap bmp = new Bitmap(image);
image.Dispose();
bmp.Save(@"C:\Documents and Settings\Joe\My Documents\My Pictures\"+strimage+" ");
pbpart.Image = bmp;
answered 8 months ago by:
15
answered 8 months ago by:
1699