简体   繁体   English

使用MigraDoc将ZedGraph转换为PDF

[英]ZedGraph to PDF using MigraDoc

I am currently working on a C# application that aims to do some computation and output graphs in a pdf file. 我目前正在开发一个C#应用程序,旨在在pdf文件中进行一些计算和输出图形。

I use the Zedgraph library to draw my graphs so something like graphPane.AddCurve(PointPairList). 我使用Zedgraph库绘制图形,例如graphPane.AddCurve(PointPairList)。 Now I tried to output these graphs to pdf file via MigraDoc package. 现在,我尝试通过MigraDoc软件包将这些图形输出为pdf文件。

Currently, I have a script that map the Zedgraph to bitmap then paste it on the pdf file. 当前,我有一个脚本,可将Zedgraph映射到位图,然后将其粘贴到pdf文件中。 So something like this: 所以像这样:

private Bitmap getBitMap()
{

  ZedGraphControl graph = new ZedGraphControl();

  newGraph = graphPane.Clone();

  SizeF s = new SizeF(3.5f, 4.5f);
  newGraph.Scale(s);

  newGraph.DrawToBitmap(bit, new Rectangle(0, 0, newGraph.Width,    newGraph.Height));

  return bit;

}

The problem is that this give me a slightly pixellated image on the pdf page. 问题是,这给了我pdf页面上稍微像素化的图像。 And I need this graph to be in a very high quality. 我需要这张图非常高质量。 So are there anything I can change the improve the quality or do i have to change my entire approach for such thing. 因此,有什么我可以改变提高质量的方法吗?或者我必须改变整个方法来解决这种问题。

Thank you so much in advance. 提前非常感谢您。

By default a Bitmap you create has your current screen resolution which could be as low as 75dpi , more common 96dpi ; 默认情况下,您创建的Bitmap具有当前屏幕分辨率 ,该分辨率可能低至75dpi ,更常见的是96dpi more modern monitors have 120dpi or more, but a good print quality starts 150dpi . 较新的显示器具有120dpi或更高的120dpi ,但良好的打印质量始于150dpi For really crips images you want 300dpi and to allow zooming you may want to have 600dpi or more.. 对于真正的图像图像,您需要300dpi ,要进行缩放,则可能需要600dpi或更高。

So you need to create and fill a bitmap with a larger size and take control of its dpi resolution. 因此,您需要创建一个更大的位图并填充它,并控制其dpi分辨率。

Assuming your size of 3.5fx 4.5f is inches, for 300dpi you need a Bitmap with 1050 x 1350 pixels. 假设3.5fx 4.5f的尺寸为英寸,则对于300dpi您需要1050 x 1350像素的Bitmap

So you should create such a Bitmap ..: 因此,您应该创建这样的Bitmap ..:

Bitmap bmp = new Bitmap(1050, 1350);

..and set the resolution: ..并设置分辨率:

bmp.SetResolution(300, 300);

To fill it up your control must have the same size: 要填充它,您的控件必须具有相同的大小:

newGraph.ClientSize = bmp.Size;

Now DrawToBitmap should create an image that is crisp and fit to zoom in.. 现在, DrawToBitmap应该创建清晰且适合放大的图像。

Note that it does not matter if the control is too large to fit on the screen; 请注意,控件是否太大而不适合显示在屏幕上都没有关系。 DrawToBitmap will still work. DrawToBitmap仍然可以使用。

Update In addidtion to a sufficient resolution it is of interest to draw quality lines etc.. A speciality of ZedGraph is that one can turn on Antialiasing , either for individual lines: 更新除了要有足够的分辨率外,还要画出高质量的线条等。ZedGraph的一个特色是可以为每条线条打开Antialiasing

curve_x.Line.IsAntiAlias = true;

or other elements: 或其他元素:

myPane.XAxis.Scale.FontSpec.IsAntiAlias = true;

or the whole Chart: 或整个图表:

zedGraphControl1.IsAntiAlias = true;

All examples are taken from this post . 所有示例均摘自本文

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM