Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application ,i want to Add some dynamic text to my the Current image. So each time When i open the Form the image need to edit and display. First time when i open the Form ,all will work properly.But when i open it for 2 nd time,it won't. I checked all the privileges for the folder ,everything is fine. But still am getting the error "A generic error occurred in GDI+". Please help me to Find out the solution



C#
using (MemoryStream ms = new MemoryStream(img))
{
    Image img1 = Image.FromStream(ms);
    Bitmap bitmap = img1 as Bitmap;
    graphics.DrawString("Dynamic Text", font, brush, atpoint, sf)
    graphics.Dispose();
    Bitmap SavingObject = new Bitmap(bitmap);
    SavingObject.Save(@path + "\\" + ImagePath,System.Drawing.Imaging.ImageFormat.Jpeg);
    bitmap.Dispose();
    img1.Dispose();
}
Posted
Updated 2-Oct-14 23:01pm
v2
Comments
BillWoodruff 3-Oct-14 6:00am    
Where is the 'graphics object coming from that you use here ?
Sinisa Hajnal 3-Oct-14 6:43am    
You should call dispose for various resources in Finally block so that resources are cleared even on error.

You're probably disposing an object and not creating it again on second opening of the form.
[no name] 3-Oct-14 16:14pm    
Since "bitmap = img1 as Bitmap", it looks like the code is disposing img1 twice.

Likely needs a SavingObject.Dispose().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900