问题描述
我在写一个软件测量数据的可视化。为此,我使用System.Windows.Forms.DataVisualization.Charting.Chart,我知道我可以chartObj.SaveImage获得的图像显示,将其存储到文件中。
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.
我的软件应具备哪些图片应该包括一个PDF导出。对于这一点,我使用iTextSharp的。同样,我知道如何把我已经保存在一个文件分割成iTextSharp.text.Image.GetInstance PDF格式的图片。
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.
所以,现在我可以拿图表的图片,把它放在一个文件(如.jpg文件),并重新加载此文件把它放在我的PDF。现在我正在寻找一个不错的解决方案,得到的图片到PDF,而不将其存储到一个文件中,可能通过一个Stream或类似的东西。我试过很长一段时间,但到现在为止我没有成功。我认为像
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);
据我了解,我无法在把从chartObj图片到一个流,而不是文件。如果我有这个,我想我可以通过加载的iTextSharp.text.Image.GetInstance流。
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.
有没有人一些帮助,你可以提供?猜猜它并不难,但我是新的C#和也iText的,所以我只是有点stucked这里。
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.
在此先感谢每想你对此
安娜
推荐答案
SaveImage到一个MemoryStream!
SaveImage to a MemoryStream:
using (var chartimage = new MemoryStream())
{
chart.SaveImage(chartimage, ChartImageFormat.Png);
return chartimage.GetBuffer();
}
从:
的 Microsoft图表控件与iTextSharp的和ASP.NET MVC
From:Microsoft Chart Controls to PDF with iTextSharp and ASP.NET MVC
这篇关于我怎么可能会DataVisualization.Charting.Chart到iTextSharp.text.Image的形象,而不写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!