当前位置: 首页 > 编程语言 > C#

保存更高分辨率的图表而不会弄乱外观分享

时间:2023-04-10 21:48:32 C#

C#学习教程:在不破坏外观的情况下保存更高分辨率的图我只是有一个关于Windows图表控件的问题,因为我遇到了一个相当愚蠢的问题。我有一个程序有一些报告,包括漂亮的窗口图表来表示一些数据。但是,我一直将这些图表保存到文件中并用于各种用途,只需使用以下内容:chart2.SaveImage(savefilename,ChartImageFormat.Png);我的第一个问题是,如果不先增加Chart控件的大小以将其保存为更高分辨率,我不确定如何执行此操作。拥有合理质量的图像会很好。第二个问题是,当我确实增加图表控件的大小时,可用的操作似乎只会增加实际图表的大小,而不是标签或文本。如果我可以手动更改所有这些,这将不是问题,这就是我对条形图所做的,但有一条线我不知道如何变粗:饼图上的标签线。我在下图中画了一个箭头:http://www.bolinger.ca/chart.png所以当图表增加到一个合理的分辨率时,这条线几乎看不见,因为它没有增加到适当的相对大小.我觉得应该有办法改变这一点,但无法弄清楚它会是什么。再次原谅我的无知。如果这两个问题中的任何一个都能得到解决,我就可以高枕无忧了,因为饼图看起来不错。谢谢!在窗体上创建/复制隐藏(Visible=false)图表对象。您甚至可以将其Top和Left属性设置为不在表单中。将此控件设置为非常高的宽度和高度(即2100x1500)...根据您的规格填充和格式化。一定要增加字体大小等。然后从隐藏的图表中调用SaveImage()或DrawToBitmap()...保存此文件时,它基本上足够高的分辨率,可以用于大多数文字处理、桌面栏、打印等。例如,2100x1500@300dpi=7"x5"用于打印...在您的应用程序中,您还可以缩小或打印它:缩小“增加”分辨率并使图像更清晰。放大会使图像模糊或模糊。我不得不依赖这种技术,因为它是从.Net图表控件获取高分辨率图表以进行打印或保存的最一致的方法……这是一个经典的作弊,但它有效:)示例:privatevoidcmdHidden_??Click(object发件人,EventArgse){System.Windows.Forms.DataVisualization.Charting.TitlechtTitle=newSystem.Windows.Forms.DataVisualization.Charting.Title();System.Drawing.FontchtFont=newSystem.Drawing.Font("宋体",42);string[]seriesArray={"A","B","C"};int[]pointsArray={1,7,4};chart1.Visible=false;chart1.Width=2100;chart1.Height=1500;chart1.Palette=System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Bright;chtTitle.Font=chtFont;chtTitle.Text="人口统计比较";chart1.Titles.Add(chtTitle);chart1.Series.Clear();//populatechartfor(inti=0;itrysettingchart2.RenderTransform=newScaleTransform(10,10)andsave.这也应该让你的线更大。这就是我为更大的图表制作的类,保存,然后恢复图形。对我来说效果很好。以上就是C#学习教程:保存更高分辨率的图表不乱码分享的全部内容,如果对大家有用还需要详细了解C#学习教程,希望大家多多关注---使用系统;使用System.Collections.Generic;使用System.Linq;使用系统文本;使用System.Threading.Tasks;使用OfficeOpenXml.Drawing;使用OfficeOpenXml.Drawing.Chart;使用System.Drawing.Imaging;数据可视化。图表;使用System.Windows.Forms;namespaceSimple_Grapher{classsaveQualityChartImage{CharttheChart;System.Drawing.FontoldFont1=newSystem.Drawing.Font("TrebuchetMS",35F,System.Drawing.FontStyle.Bold);System.Drawing.FontoldFont2=newSystem.Drawing.Font("TrebuchetMS",15F,System.Drawing.FontStyle.Bold);System.Drawing.FontoldFont3=newSystem.Drawing.Font("TrebuchetMS",35F,System.Drawing.FontStyle.Bold);System.Drawing.FontoldLegendFont=newSystem.Drawing.Font("TrebuchetMS",35F,System.Drawing.FontStyle.Bold);intoldLineWidth1;旧线宽4;国际醇宽度;int旧高度;publicsaveQualityChartImage(ChartinputChart){if(!(inputChart.Series.Count>0)){返回;}theChart=inputChart;如果(inputChart.Titles.Count>0){oldFont1=inputChart.Titles[0].Font;}oldFont2=inputChart.ChartAreas[0].AxisX.LabelStyle.Font;oldFont3=inputChart.ChartAreas[0].AxisX.TitleFont;如果(theChart.Legends.Count>0){oldLegendFont=theChart.Legends["Legend"].Font;}oldLineWidth1=theChart.ChartAreas[0].AxisX.LineWidth;oldLineWidth2=theChart.ChartAreas[0].AxisX.MajorTickMark.LineWidth;oldLineWidth3=theChart.Series[0].BorderWidth;oldLineWidth4=theChart.ChartAreas[0].AxisY.MajorGrid.LineWidth;oldWidth=theChart.Width;oldHeight=theChart.Height;保存图片();}publicvoidsaveimage(){theChart.Visible=false;System.Drawing.FontchtFont=newSystem.Drawing.Font("TrebuchetMS",35F,System.Drawing.FontStyle.Bold);System.Drawing.FontsmallFont=newSystem.Drawing.Font("TrebuchetMS",15F,System.Drawing.FontStyle.Bold);如果(theChart.Titles.Count>0){theChart.Titles[0].Font=chtFont;}theChart.ChartAreas[0].AxisX.TitleFont=chtFont;theChart.ChartAreas[0].AxisX.LineWidth=3;theChart.ChartAreas[0].AxisX.MajorGrid.LineWidth=3;theChart.ChartAreas[0].AxisX.LabelStyle.Font=smallFont;theChart.ChartAreas[0].AxisX.MajorTickMark.LineWidth=3;theChart.ChartAreas[0].AxisY.TitleFont=chtFont;theChart.ChartAreas[0].AxisY.LineWidth=3;theChart.ChartAreas[0].AxisY.MajorGrid.LineWidth=3;theChart.ChartAreas[0].AxisY.LabelStyle.Font=smallFont;theChart.ChartAreas[0].AxisY.MajorTickMark.LineWidth=3;如果(theChart.Legends.Count>0){theChart.Legends["图例"].Font=smallFont;}foreach(Chart.Series中的Series系列){series.BorderWidth=3;}theChart.Width=1800;theChart.Height=1200;SaveFileDialogsave=newSaveFileDialog();save.DefaultExt=".png";if(save.ShowDialog()==DialogResult.OK){theChart.SaveIm年龄(保存。文件名,ChartImageFormat.Png);}重置旧值();}privatevoidresetOldValues(){if(theChart.Titles.Count>0){theChart.Titles[0].Font=oldFont1;}theChart.ChartAreas[0].AxisX.TitleFont=oldFont3;theChart.ChartAreas[0].AxisX.LineWidth=oldLineWidth1;theChart.ChartAreas[0].AxisX.MajorGrid.LineWidth=oldLineWidth4;theChart.ChartAreas[0].AxisX.LabelStyle.Font=oldFont2;theChart.ChartAreas[0].AxisX.MajorTickMark.LineWidth=oldLineWidth2;theChart.ChartAreas[0].AxisY.TitleFont=oldFont3;theChart.ChartAreas[0].AxisY.LineWidth=oldLineWidth1;theChart.ChartAreas[0].AxisY.MajorGrid.LineWidth=oldLineWidth4;theChart.ChartAreas[0].AxisY.LabelStyle.Font=oldFont2;theChart.ChartAreas[0].AxisY.MajorTickMark.LineWidth=oldLineWidth2;如果(theChart.Legends.Count>0){theChart.Legends["图例"].Font=oldLegendFont;}foreach(Chart.Series中的系列系列){series.BorderWidth=oldLineWidth3;}theChart.Width=oldWidth;theChart.Height=oldHeight;theChart.Visible=true;}}}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如有转载请注明出处: