[英]How may I get the image of DataVisualization.Charting.Chart to iTextSharp.text.Image without writing to a file?
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.
为此,我使用System.Windows.Forms.DataVisualization.Charting.Chart,我知道我可以通过chartObj.SaveImage获取显示的图像以将其存储到文件中。
My software shall have a PDF export in which the picture should be included. 我的软件应具有PDF导出功能,其中应包含图片。 For this, I'm using iTextSharp.
为此,我正在使用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.
同样,我确实知道如何通过iTextSharp.text.Image.GetInstance将存储在文件中的图片放入PDF。
So by now I am able to take the picture of the chart, put it to a file (eg a .jpg file) and load this file again to put it in my PDF. 因此,现在我可以拍摄图表的图片,将其放入文件(例如.jpg文件)中,然后再次加载此文件以将其放入我的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.
现在,我正在寻找一个不错的解决方案,以将图片放入PDF而不将其存储到文件中,例如通过Stream或类似的方式。 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. 据我了解,我无法将chartObj中的图片放入Stream中而不是文件中。 If I had this, I guess I could load the Stream via iTextSharp.text.Image.GetInstance.
如果有这个功能,我想我可以通过iTextSharp.text.Image.GetInstance加载Stream。
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.
猜猜并没有那么难,但是我对C#和iText还是陌生的,所以我在这里有些卡住了。
Thanks in advance for every thought you have about this! 预先感谢您对此的所有想法!
Anna 安娜
SaveImage to a MemoryStream: 将图片保存到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 从: Microsoft图表控件到带iTextSharp和ASP.NET MVC的PDF
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.