Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to save an image of a chart in WPF so that the chart can be viewed without running my application. How would I do this?

[OP to supply the details of the charting component he's using]
Posted
Updated 17-May-12 0:22am
v3

You don't save the charts, you save the data that is used to make the charts. There's no need to save the actual chart because it is simply a visual representation of the data.
 
Share this answer
 
Comments
sankar6664 17-May-12 5:32am    
I want to store the Chart also...
Pete O'Hanlon 17-May-12 5:36am    
Why? What business problem are you trying to solve? If you save the data, you can simply recreate the chart the next time you open it.
sankar6664 17-May-12 5:39am    
I am doing my project work in a private company.
In that project work,I am going to show that chart as a image.
Pete O'Hanlon 17-May-12 5:50am    
Is this in hard copy, or still in the Silverlight window? If it's hard copy, just take a screen shot.
sankar6664 17-May-12 5:57am    
It is in the format of chart in wpf window
Saints preserve us. OK, as you haven't specified a chart component, and given that my previous answer to you lead to a conversation that was an exercise in complete futility, here's the code I would use to save a visual element out to file.
C#
int chartWidth = (int)chart.ActualWidth;
int chartHeight = (int)chart.ActualHeight;
double resolution = 96d;
RenderTargetBitmap bmp = new RenderTargetBitmap(chartWidth, chartHeight, resolution, resolution, PixelFormats.Pbgra32);
bmp.Render(chart);
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
encoder.Save(...my file stream ...);
I've left out the code for creating the stream - you really should be able to figure that one out for yourself, and I've made assumptions that you want a 96x96 DPI image.
 
Share this answer
 
Comments
sankar6664 17-May-12 8:04am    
Elaborate Please
Pete O'Hanlon 17-May-12 8:13am    
Look. I've written the code for you. It's now time for you to do some work. If you can't figure out what this is doing from looking things up then I can't help you. I have spent more time molly coddling and hand holding for you than I have for just about anyone else. I AM NOT YOUR PERSONAL TUTOR. I AM NOT YOUR TEACHER and I AM NOT GOING TO WRITE ALL YOUR CODE FOR YOU.
sankar6664 17-May-12 8:16am    
OK.
By the way,Thank you for giving your valuable time to me...
Bye...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900