Page 1 of 1
Issue with chart printing
Posted: Wed Oct 27, 2010 3:57 pm
by 13047055
I have a requirement to output to a print document, which is working to a point with the following code:
Code: Select all
Stream CO2PlotStream = new MemoryStream();
tcCO2Plot.Export.Image.PNG.Save(CO2PlotStream);
Image CO2PlotImage = Image.FromStream(CO2PlotStream);
This is then drawn on the print engine in the OnPrint event where Bounds is the calculated page bounds.
Code: Select all
e.Graphics.DrawImage(Image, Bounds);
However, the image appears fuzzy - see the attached screenshot of the resultant document in PDF form.
- Extract from Print call
- PDF Report ScreenCap.png (87.78 KiB) Viewed 4201 times
Contrast with a clipboard copy to Word and PDF - The clipboard copy is generated with the following code
Code: Select all
Chart.Export.Image.Metafile.CopyToClipboard();
And produces the following when PDFd (and screen cap'd)...
- PDF Clipboard ScreenCap.png (55.87 KiB) Viewed 4176 times
Any suggestions as to how I can improve the printing to be more like the copy?
TIA Bernie
Re: Issue with chart printing
Posted: Thu Oct 28, 2010 10:10 am
by 10050769
Hello Bernie,
I think you can use different formats of Metafile, allowing you export higher quality images. You can do something as next:
Code: Select all
private void button1_Click(object sender, EventArgs e)
{
tChart1.Export.Image.Metafile.EMFFormat = System.Drawing.Imaging.EmfType.EmfOnly;
tChart1.Export.Image.Metafile.Save(@"teeChartEmfOnly.emf");
tChart1.Export.Image.Metafile.EMFFormat = System.Drawing.Imaging.EmfType.EmfPlusDual;
tChart1.Export.Image.Metafile.Save(@"teeChartEmfPlusDual.emf");
tChart1.Export.Image.Metafile.EMFFormat = System.Drawing.Imaging.EmfType.EmfPlusOnly;
tChart1.Export.Image.Metafile.Save(@"teeChartEmfPlusOnly.emf");
}
Also, If you prefer use CopyToClipBoard() method, I recommend you use PNG format,so get a good results when do this. See next example:
Code: Select all
private void InitializeChart()
{
Steema.TeeChart.Styles.ErrorBar series1 = new Steema.TeeChart.Styles.ErrorBar(tChart1.Chart);
tChart1.Aspect.View3D = false;
series1.FillSampleValues();
series1.ColorEach = true;
tChart1.Export.Image.PNG.CopyToClipboard();
}
I hope will helps.
Thanks,
Re: Issue with chart printing
Posted: Thu Oct 28, 2010 10:43 am
by 13047055
Hi Sandra,
The clipboard copy is working fine - the issue is with the printed output. Now, I'm a bit of a newbie at printing in C#, but it seems to me that I need an Image object to pass to the Graphics.DrawImage method in the PrintDocument OnPrint event handler. I'm generating this image using the tcChart.Export.Image method into a memory stream, then creating an image object from that. Now, Graphics.DrawImage is scaling the image to fit the specified bounds, but that is not the root cause of the problem - using Graphics.DrawImageUnscaled generates this.
- PDF Report ScreenCap Unscaled.png (93.15 KiB) Viewed 4152 times
As you can see, this is still blury although the font proportions are now better. I think I need to be able to control the size of the image I generate - is this possible? Or do you have a better way of getting something I can use with a Graphics object?
As usual, all suggestions appreciated!
Bernie
Re: Issue with chart printing
Posted: Thu Oct 28, 2010 1:00 pm
by 10050769
Hello Bernie,
You could change size of image you would export, using properties Width and Height of Image as do in below code:
Code: Select all
tChart1.Export.Image.PNG.Width = 200;
tChart1.Export.Image.PNG.Height = 100;
tChart1.Export.Image.PNG.CopyToClipboard();
I hope will helps.
Thanks,