开发者

How to set the resolution (DPI) for Microsoft Chart Control generated Images in asp.net

开发者 https://www.devze.com 2023-03-24 01:11 出处:网络
How can I define the image resolution (in DPI) for images created by开发者_StackOverflow the microsoft chart controls for .net (for the creation of .png-images).

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

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?

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)));
}


If you rephrase your question as "how to get around annoying jpeg raster artifacts" I output mine as a png using the GetBytes method. I then use the constructor to set height/width.

Chart chart = new Chart(width: 1200, height: 600, theme: ChartTheme.Blue);
...
chart.GetBytes("png");

if you are curious I use it this way in a .net MVC extension method and base 64 encode into a image

return "data:image/png;base64," + System.Convert.ToBase64String(chart.GetBytes("png"));
0

精彩评论

暂无评论...
验证码 换一张
取 消