Hello!
I'm trying to take a PNG file, which contains Chart rendered in PNG, using class
Code:
MigraDoc.RtfRendering.ChartRendering
.
There are method
StoreTempImage, which provides the similar functionality. So, I create helper class, using this method
Code:
public void Render(string path)
{
try
{
float resolution = 96;
int horzPixels = (int)(_chart.Width.Inch * resolution);
int vertPixels = (int)(_chart.Height.Inch * resolution);
Bitmap bmp = new Bitmap(horzPixels, vertPixels);
#if true
XGraphics gfx = XGraphics.CreateMeasureContext(new XSize(horzPixels, vertPixels), XGraphicsUnit.Point, XPageDirection.Downwards);
//XGraphics gfx = XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels));
#else
#if GDI
XGraphics gfx = XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels));
#endif
#if WPF
// TODOWPF
XGraphics gfx = null; //XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels));
#endif
#endif
//REM: Should not be necessary:
gfx.ScaleTransform(resolution / 72);
//gfx.PageUnit = XGraphicsUnit.Point;
DocumentRenderer renderer = new DocumentRenderer(_chart.Document);
renderer.RenderObject(gfx, 0, 0, _chart.Width.Point, _chart);
bmp.SetResolution(resolution, resolution);
bmp.Save(path, ImageFormat.Png);
}
catch (Exception)
{
return;
}
}
it works ok, but there are some problems. Images (as you can see in related file), cut off on bottom. Also there is bad font rendering.
What am I doing wrong? )
Thanks.