Reputation: 141
In my application, I have a chart (WPF Toolkit) in normal resolution/size (for example 640x480). I want to export this chart to an image in different resolutions (for example 800x600 or greater).
Currently, I use these lines of codes:
var path = String.Format(@"C:\Temp\chart-{0}.bmp", DateTime.Now.Ticks);
var renderBitmap = new RenderTargetBitmap((int)xamChart.ActualWidth,
(int)xamChart.ActualHeight,
96d,
96d,
PixelFormats.Pbgra32);
renderBitmap.Render(xamChart);
// Create a file stream for saving image
using (var outStream = new FileStream(path, FileMode.Create))
{
// Use png encoder for our data
var encoder = new BmpBitmapEncoder();
// push the rendered bitmap to it
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
// save the data to the stream
encoder.Save(outStream);
}
It works very well, but if I want to save in greater resolution, I need to change size of the chart. These changes of sizes are visible on my form and are not acceptable. Is there a way to keep the original size of the element and save it as an image in different sizes?
PS. I don't want save the chart to an image in its original size and in then change the image size, because I lose image quality.
PPS. Second solution: Maybe someone knows how to export a WPF element to vector graphics?
Upvotes: 2
Views: 796
Reputation: 6275
I have not tried it at all but it might be possible to do what you ask by increasing the DPI(the forth and fifth argument to RenderTargetBitmap
)
Upvotes: 1