Saving image

I am trying to save a diagram to an XML file. I have custom images I need to write to the XML file. I am doing …
MemoryStream stream = new MemoryStream();
((GoImage)(((GoIconicNode)obj).Icon)).Image.Save(stream, ImageFormat.Jpeg);
writer.WriteAttributeString(“icon”, ConvertImageToBase64(stream));
The 2nd line fails with “A generic error occurred in GDI+”. Any ideas what is wrong? Is there something special about the Image in GoImage I need to take account of?

I don't know what might be wrong. Here's a snippet of code adapted from our SVG generator: Image image = aGoImage.Image; if (image != null && image.Width > 0 && image.Height > 0) { MemoryStream stream = new MemoryStream(); image.Save(stream, ImageFormat.Png); stream.Close(); byte[] bdata = stream.GetBuffer(); String data = "data:image/png;base64," + Convert.ToBase64String(bdata); . . . }

Walter, How about in Load routine?

I’ve found the problem. The image was in a Datagrid (Janus) and while the code was happy to show it in GoDiagram, it did not like being save to a stream.
When I created a new instance of the image and then saved it to a stream it was happy.
The Microsoft error message was not help at all!

Hi

Has anyone had sucess in loading back the image from the xml file?

This worked the first time I tried it:
String b64data = “iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4 c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHU wAADqYAAAOpgAABdwnLpRPAAAAJFJREFUOE+9U1sOgCAM4+h+cS5uhm5aKI8 SiYlLzEK2PjYwhB8jX1r2DSEL1JlTSpqAilMFU7aQDlAUKjnGuHbQKUDJM8C vHIDI/VbLTrTcARrupgP4Jj/zLxdelFZEnbPpKyo7UER2KWokL/DW7cxEBlY E3mjBmWcHWSWtL3MAE5DnbK4YBaW49Zsx8xbwc/MJbVEi6NP7640AAAAASUV ORK5CYII=”;
byte[] idata = Convert.FromBase64String(b64data);
MemoryStream istream = new MemoryStream();
istream.Write(idata, 0, idata.Length);
istream.Position = 0;
Image memimg = Image.FromStream(istream);
GoImage goimg = new GoImage();
goimg.Image = memimg;
goimg.Bounds = new RectangleF(110, 10, 16, 16);
doc.Add(goimg);