Wpf 将OxyPlot PlotModel导出到ReportDocument会产生模糊图像
长期潜伏者,第一次海报 我目前正在开发一个WPF应用程序,它利用OxyPlot生成一个图形。我希望将生成的图形导出到ReportDocument(RDLC)中,并使用CutePdf将其打印为PDF。我能够成功地做到这一点 目前,我采取的方法是执行下面的代码段Wpf 将OxyPlot PlotModel导出到ReportDocument会产生模糊图像,wpf,pdf,rdlc,oxyplot,reportdocument,Wpf,Pdf,Rdlc,Oxyplot,Reportdocument,长期潜伏者,第一次海报 我目前正在开发一个WPF应用程序,它利用OxyPlot生成一个图形。我希望将生成的图形导出到ReportDocument(RDLC)中,并使用CutePdf将其打印为PDF。我能够成功地做到这一点 目前,我采取的方法是执行下面的代码段 using (var memStream = new MemoryStream()) { PngExporter.Export(PlotModel, memStream, 850, 700, OxyColors.White, 120)
using (var memStream = new MemoryStream())
{
PngExporter.Export(PlotModel, memStream, 850, 700, OxyColors.White, 120);
var fromStream = Image.FromStream(memStream);
fromStream.Save(memStream, ImageFormat.Png);
imageArray = new byte[memStream.Length];
memStream.Seek(0, SeekOrigin.Begin);
memStream.Read(imageArray, 0, (int) memStream.Length);
}
var stringBytes = Convert.ToBase64String(imageArray);
要将其传递给RDLC,我必须将内存流转换为Base64String,并将其作为参数传递。因此
var parameter = new ReportParameter("Chart", stringBytes);
reportViewer.LocalReport.SetParameters(parameter);
然而,尽管这一切都很好,但当我放大PDF时,PDF中的图像输出似乎非常模糊和像素化,而页面上的周围文本却清晰可见
我尝试过将图像以PNG/BMP/JPG的形式保存到磁盘上,但这似乎也会返回模糊的图像,因此这不是大小问题
using (var stream = File.Create("testChart.png"))
{
var pngExporter = new PngExporter();
pngExporter.Export(PlotModel, stream);
}
我在这篇文章中加入了PDF格式,以说明我的意思
谢谢 链接不再工作了。你解决过这个问题吗?@PortlandRunner-嗨!我设法失去了访问的权限,所以只看到了你的问题。是的,我确实设法解决了。我必须使用
PngExporter.ExportToBitMap
将其导出到.png,然后使用.NET的BmpBitmapEncoder
对其进行转换,设置分辨率,将位图流传递到Image.FromStream
并将其作为字节[]
返回。我不能给出精确的代码,因为这是工作解决方案的一部分,但大量的实验确实起到了作用:)