简体   繁体   English

如何在不写入文件的情况下将DataVisualization.Charting.Chart的图像获取到iTextSharp.text.Image?

[英]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.

相关问题 如何将iTextSharp.text.Image大小调整为我的代码? - How to resize an iTextSharp.text.Image size into my code? DataVisualization.Charting.Chart PostPaint事件过早触发 - DataVisualization.Charting.Chart PostPaint Event Firing Prematurely 将iTextSharp.text.Image转换回System.Drawing.Image - Converting iTextSharp.text.Image back to System.Drawing.Image 从顶部剪切jpg iTextSharp.text.Image - Cut jpg iTextSharp.text.Image From top 如何创建一个iTextSharp.text.Image对象startng到System.Drawing.Bitmap对象? - How to create a iTextSharp.text.Image object startng to a System.Drawing.Bitmap object? 是否可以以十六进制显示DataVisualization.Charting.Chart的x轴值? - Is it possible to display the x-axis values of the DataVisualization.Charting.Chart in hexadecimal? SVG渲染引擎DLL和iTextSharp.text.Image - 转换url拍摄的图像svg - SVG Rendering Engine DLL & iTextSharp.text.Image - Convert image svg taken by url 从System.Drawing.Image创建iTextSharp.text.Image [GetInstance重载不可用] - Create an iTextSharp.text.Image from System.Drawing.Image [GetInstance overload not available] 来自C#System.Web.UI.DataVisualization.Charting.Chart帮助程序的图像映射 - Image map from C# System.Web.UI.DataVisualization.Charting.Chart helper 调整图表大小后如何为datavisualization.charting调整轴刻度? - How to adjust axis scales for datavisualization.charting after resizing a chart?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM