I have a requirement to save a chart as an image to a Crystal Report. I can pass a byte[] of the image using ExportToBitmapSource() and then converting this to a byte array using a MemoryStream. However, quality is significantly lost in the process. Here is an example of my source.
MyChart.RenderPriority = RenderPriority.Immediate;
MyChart.ZoomExtents();
var bitmap = MyChart.ExportToBitmapSource();
using (MemoryStream stream = new MemoryStream())
{
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
encoder.Save(stream);
byte[] bytes = stream.ToArray();
}
Later on I set the value of a blob field of the dataset passed to the Crystal Report to this byte array.
Quality of the image is pretty good when I save directly to file, but most important when I use the MyChart.ExportToFile() I actually lose some of the markup annotations when I set the “useXamlRenderSurface” to true. I.e. I have custom text markups that show a border and the border doesn’t get saved with the image.
The thing about the Crystal Report is that our report designer can set the actual size of the image to be shown in terms of inches. If I am able to save/export the chart image in those same proportions I believe the image would look fine since it wouldn’t be getting stretched in the report.
Suggestions?
- Chris Kirkman asked 5 years ago
- You must login to post comments
Please login first to submit.