How may I get the image of DataVisualization.Charting.Chart to iTextSharp.text.Image without writing to a file?

纵然是瞬间 提交于 2019-12-12 11:34:22

问题


I'm writing a piece of software for visualization of measurement data. For this I use System.Windows.Forms.DataVisualization.Charting.Chart and I do know that I can get the shown image by chartObj.SaveImage to store it to a file.

My software shall have a PDF export in which the picture should be included. For this, I'm using iTextSharp. Again, I do know how to put a picture which I have stored in a file into the PDF by iTextSharp.text.Image.GetInstance.

So by now I am able to take the picture of the chart, put it to a file (e.g. a .jpg file) and load this file again to put it in my PDF. Now I'm looking for a nice solution to get the picture into the PDF without storing it into a file, maybe through a Stream or something like that. I've tried quite some time, but until now I didn't succeed. I've thought of something like

Stream imageStream = image of chartObj;
iTextSharp.text.Image picture = iTextSharp.text.Image.GetInstance(imageStream);

As far as I understand, I fail in putting the picture from the chartObj into a Stream instead of a file. If I had this, I guess I could load the Stream via iTextSharp.text.Image.GetInstance.

Has anyone some help you could offer? Guess it's not that difficult, but I'm new to C# and also to iText, so I'm just a bit stucked here.

Thanks in advance for every thought you have about this!

Anna


回答1:


SaveImage to a MemoryStream:

using (var chartimage = new MemoryStream())
  {
    chart.SaveImage(chartimage, ChartImageFormat.Png);
    return chartimage.GetBuffer();
  }

From: Microsoft Chart Controls to PDF with iTextSharp and ASP.NET MVC



来源:https://stackoverflow.com/questions/12582608/how-may-i-get-the-image-of-datavisualization-charting-chart-to-itextsharp-text-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!