Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Common causes of: A generic error occurred in GDI+ (Read 3093 times)
Chris B.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Joined: May 30th, 2013
Common causes of: A generic error occurred in GDI+
Aug 29th, 2013 at 3:03am
Print Post  
Hi,

May we know the common causes and resolutions to the following error: "A generic error occurred in GDI+." when trying to export diagram to image using:

            string path = Server.MapPath(@"~\Export\Images\");
            System.Drawing.Image image = diagram.CreateImage();            
            image.Save(path + Session.SessionID + ".bmp");
            image.Dispose();

It occurs occasionally and we were not able to deduce reasonable pattern of the causes.

It is a requirement for us to export to image (not PDF or other types) since we want to use back in a Word document.

On the other hand, we tried to use diagram.SaveToString() or diagram.SaveToStream() as alternatives, but we were not able to regenerate the image from resulting base64 string. Kindly advise us.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Common causes of: A generic error occurred in GDI+
Reply #1 - Aug 29th, 2013 at 7:37am
Print Post  
Hi,

Does it happen on the diagram.CreateImage or Image.Save line?

CreateImage might be throwing an exception if the image gets very large. GDI+ cannot create bitmaps larger than about 3000 x 3000 pixels. In that case, you will have to split the diagram into smaller images, e.g. loop over its full size, on each iteration set Diagram.Bounds to a smaller rectangle so that all rectangles cover the original Bounds, and export an image part using the smaller Bounds.

If the exception is thrown by Save, check if you have write access to the folder, or if the file doesn't already exist and is open by another thread or process.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint