PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 10:20 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri Jul 26, 2013 11:53 am 
Offline

Joined: Fri Jul 26, 2013 11:31 am
Posts: 1
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.


Attachments:
testsave.png
testsave.png [ 2.66 KiB | Viewed 4569 times ]
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 143 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group