Search code examples
.netsystem.drawingmicrosoft-chart-controls

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


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).

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.


Solution

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