如何在WPF中保存各种图表? [英] How to Save Various Charts in WPF?

查看:70
本文介绍了如何在WPF中保存各种图表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在WPF中保存图表的图像,以便可以在不运行我的应用程序的情况下查看图表.我该怎么办?

[OP提供他使用的图表组件的详细信息]

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]

推荐答案

您不保存图表,而是保存用于制作图表.无需保存实际图表,因为它只是数据的直观表示.
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.


圣徒保护了我们.好的,因为您还没有指定图表组件,并且鉴于我先前对您的回答导致一次对话完全是徒劳的,所以这里是我用来将可视元素保存到文件中的代码.
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.
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 ...);

我已经省略了创建流的代码-您确实应该能够自己找出一个代码,而我已经假设您想要一张96x96 DPI图像.

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.


这篇关于如何在WPF中保存各种图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆