如何设置为Microsoft图表控件的分辨率(DPI)产生的asp.net图片设置为、图表、控件、分辨率

2023-09-04 23:16:24 作者:青春、熟悉的旋律

我如何定义图像分辨率(DPI)由Microsoft图表控件.NET创建的映像(用于创建png格式,图像)。

How can I define the image resolution (in DPI) for images created by the microsoft chart controls for .net (for the creation of .png-images).

本的WinForms版本的图表控件的有 Chart.RenderingDpi [X | Y] - 的财产,但是对于asp.net控制,我找不到这样的属性。

The winforms version of the charting control has the Chart.RenderingDpi[X|Y]- property, however for the asp.net control, I can not find such a property.

有人能导致我这样做的一个解决方案?

Can someone lead me to a solution for doing this?

更新 在寻找解决的办法,我已经看到,图表控件有油漆的方法。有了这个,我能创造与其他DPI-设置的图像。我不知道这是否是走正确的路,但结果看起来不是对我不好。我已经发布了code作为一个答案。如果任何人有一个更整洁的解决方案,请让我知道。

Update During searching for a solution, I have seen that the chart-control has a Paint-method. With this I was able to create images with other DPI-settings. I'm not sure if this is the correct way to go, but the result looks not to bad to me. I have posted the code as an answer. If anyone has a more neat solution, please let me know.

推荐答案

下面一个解决方案,我发现,产生了较好的效果。

Here a solution I have found that produces good results.

Bitmap bmp = new Bitmap(size.Width, size.Height);
bmp.SetResolution(resX,resY);
using (Graphics g = Graphics.FromImage(bmp)) {
     chart.Paint(g,new Rectangle(new Point(0,0),GetSizeOrDefault(context)));
}