Joined: 20 Dec 2006
|Posted: Wed Dec 20, 2006 4:41 am Post subject: How to convert a chart to Image in C#
public System.Drawing.Image GetImageDataFromChartDocument(XChartDocument chart)
unoidl.com.sun.star.datatransfer.XTransferable xTransfer = (unoidl.com.sun.star.datatransfer.XTransferable)chart;
unoidl.com.sun.star.datatransfer.DataFlavor df = new unoidl.com.sun.star.datatransfer.DataFlavor("image/png", "PNG", typeof(Byte));
byte imageData = (byte)xTransfer.getTransferData(df).Value;
MemoryStream ms = new MemoryStream(imageData);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
Now the problem with this, is that the size of the image is always 302x200 or something like that. If anyone knows how to get the image to match the size of the chart, I would really apreciated.
Also I'm looking for a way to convert an Image to XShape, but couldn't find any, yet. Inserting in the spreadsheet through clipboard is not an option (multithreading issues + not to mention the fact that the clipboard is shared between processes). And for now I do that using a temporary file, but I don't think the API is that limited.