// グラフ画像を保存する public static void SaveSupplyGraph(PlotModel plotModel) { var pngExporter = new OxyPlot.Wpf.PngExporter { Width = (int)plotModel.PlotArea.Width, Height = (int)plotModel.PlotArea.Height, Background = OxyColors.White }; var bitmapSource = pngExporter.ExportToBitmap(plotModel); // BitmapSourceを保存する var sfd = new SaveFileDialog { // ファイルの種類を設定 Filter = "画像ファイル(*.png)|*.png|全てのファイル (*.*)|*.*" }; // ダイアログを表示 if ((bool)sfd.ShowDialog()) { // 保存処理 using (var stream = new FileStream(sfd.FileName, FileMode.Create)) { var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); encoder.Save(stream); } } }
/// <summary> /// Сохранение результирующего графика в формат BMP /// </summary> /// <param name="path">Путь к результирующему файлу</param> /// <param name="width">Ширина рисунка</param> /// <param name="height">Высота рисунка</param> public void SavePlotToBMP(string path, int width, int height) { var pngExporter = new OxyPlot.Wpf.PngExporter { Width = width, Height = height, Background = OxyColors.White }; var bitmap = pngExporter.ExportToBitmap(PlotModel); bitmap.GetBitmap().Save(path); }
/// <summary> /// PlotModelのグラフをクリップボードにコピーする /// </summary> /// <param name="pm"></param> /// <param name="width"></param> /// <param name="height"></param> public void CopyPlot(PlotModel pm, int width = 800, int height = 600) { var pngExporter = new OxyPlot.Wpf.PngExporter { Width = width, Height = height, Background = OxyColors.White }; Application.Current.Dispatcher.Invoke((Action)(() => { var bitmap = pngExporter.ExportToBitmap(pm); Clipboard.SetImage(bitmap); })); }
private void CopyEarnedValueChartToClipboard() { lock (m_Lock) { if (CanCopyEarnedValueChartToClipboard()) { var pngExporter = new OxyPlot.Wpf.PngExporter { Width = EarnedValueChartOutputWidth, Height = EarnedValueChartOutputHeight, Background = OxyColors.White }; BitmapSource bitmap = pngExporter.ExportToBitmap(EarnedValueChartPlotModel); System.Windows.Clipboard.SetImage(bitmap); } } }
private void Print2DIDs() { string[] plots = new string[] { "MxMy", "MxN", "MyN" }; foreach (var p in plots) { var pngExporter = new OxyPlot.Wpf.PngExporter { Width = 600, Height = 400, Background = OxyColors.White }; var bitmap = pngExporter.ExportToBitmap(this.GetType().GetProperty(p + "ID").GetValue(this) as PlotModel); MemoryStream stream = new MemoryStream(); BitmapEncoder encoder = new BmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmap)); encoder.Save(stream); Bitmap bmp = new Bitmap(stream); ImageConverter converter = new ImageConverter(); byte[] output = (byte[])converter.ConvertTo(bmp, typeof(byte[])); string path = System.IO.Path.GetTempPath() + p + ".tmp"; File.WriteAllBytes(path, output); } }
public static void Generate2DIDs(Column col) { if (col.diagramVertices.Count == 0) { col.GetInteractionDiagram(); } if (col.MxMyPts.Count == 0) { col.Get2DMaps(); } LineSeries sp1 = new LineSeries() { Color = OxyColors.Black, MarkerType = MarkerType.Plus, MarkerSize = 4, MarkerStroke = OxyColors.Black, MarkerFill = OxyColors.Black, MarkerStrokeThickness = 1, LabelFormatString = "({0},{1})" }; sp1.Points.Add(new DataPoint(col.SelectedLoad.MEdx, col.SelectedLoad.MEdy)); PlotModel colMxMyID = new PlotModel() { Title = "Mx-My interaction diagram", Subtitle = "(N = " + Math.Round(col.SelectedLoad.P) + "kN)" }; colMxMyID.Axes.Add(new LinearAxis() { Position = AxisPosition.Bottom, Title = "Mx", MajorGridlineColor = OxyColors.LightGray, MajorGridlineStyle = LineStyle.Dash, MinorGridlineColor = OxyColors.LightGray, MinorGridlineStyle = LineStyle.Dash, }); colMxMyID.Axes.Add(new LinearAxis() { Position = AxisPosition.Left, Title = "My", MajorGridlineColor = OxyColors.LightGray, MajorGridlineStyle = LineStyle.Dash, MinorGridlineColor = OxyColors.LightGray, MinorGridlineStyle = LineStyle.Dash, }); LineSeries s1 = new LineSeries() { Color = OxyColors.Red, MarkerType = MarkerType.None, StrokeThickness = 1 }; foreach (var p in col.MxMyPts) { s1.Points.Add(new DataPoint(p.X, p.Y)); } colMxMyID.Series.Add(s1); colMxMyID.Series.Add(sp1); LineSeries sp2 = new LineSeries() { Color = OxyColors.Black, MarkerType = MarkerType.Plus, MarkerSize = 4, MarkerStroke = OxyColors.Black, MarkerFill = OxyColors.Black, MarkerStrokeThickness = 1, LabelFormatString = "({0},{1})" }; sp2.Points.Add(new DataPoint(col.SelectedLoad.MEdx, -col.SelectedLoad.P)); PlotModel colMxNID = new PlotModel() { Title = "Mx-N interaction diagram", Subtitle = "(My = " + Math.Round(col.SelectedLoad.MEdy) + "kN.m)" }; colMxNID.Axes.Add(new LinearAxis() { Position = AxisPosition.Bottom, Title = "Mx", MajorGridlineColor = OxyColors.LightGray, MajorGridlineStyle = LineStyle.Dash, MinorGridlineColor = OxyColors.LightGray, MinorGridlineStyle = LineStyle.Dash, }); colMxNID.Axes.Add(new LinearAxis() { Position = AxisPosition.Left, Title = "N", MajorGridlineColor = OxyColors.LightGray, MajorGridlineStyle = LineStyle.Dash, MinorGridlineColor = OxyColors.LightGray, MinorGridlineStyle = LineStyle.Dash, }); LineSeries s2 = new LineSeries() { Color = OxyColors.Blue, MarkerType = MarkerType.None, StrokeThickness = 1 }; foreach (var p in col.MxNPts) { s2.Points.Add(new DataPoint(p.X, p.Y)); } colMxNID.Series.Add(s2); colMxNID.Series.Add(sp2); LineSeries sp3 = new LineSeries() { Color = OxyColors.Black, MarkerType = MarkerType.Plus, MarkerSize = 4, MarkerStroke = OxyColors.Black, MarkerFill = OxyColors.Black, MarkerStrokeThickness = 1, LabelFormatString = "({0},{1})", }; sp3.Points.Add(new DataPoint(col.SelectedLoad.MEdy, -col.SelectedLoad.P)); PlotModel colMyNID = new PlotModel() { Title = "My-N interaction diagram", Subtitle = "(Mx = " + Math.Round(col.SelectedLoad.MEdx) + "kN.m)", }; colMyNID.Axes.Add(new LinearAxis() { Position = AxisPosition.Bottom, Title = "My", MajorGridlineColor = OxyColors.LightGray, MajorGridlineStyle = LineStyle.Dash, MinorGridlineColor = OxyColors.LightGray, MinorGridlineStyle = LineStyle.Dash, }); colMyNID.Axes.Add(new LinearAxis() { Position = AxisPosition.Left, Title = "N", MajorGridlineColor = OxyColors.LightGray, MajorGridlineStyle = LineStyle.Dash, MinorGridlineColor = OxyColors.LightGray, MinorGridlineStyle = LineStyle.Dash, }); LineSeries s3 = new LineSeries() { Color = OxyColors.Green, MarkerType = MarkerType.None, StrokeThickness = 1 }; foreach (var p in col.MyNPts) { s3.Points.Add(new DataPoint(p.X, p.Y)); } colMyNID.Series.Add(s3); colMyNID.Series.Add(sp3); if (col.FireDesignMethod == FDesignMethod.Advanced) { LineSeries spf1 = new LineSeries() { Color = OxyColors.Black, MarkerType = MarkerType.Plus, MarkerSize = 4, MarkerStroke = OxyColors.Black, MarkerFill = OxyColors.Black, MarkerStrokeThickness = 1, LabelFormatString = "fire ({0},{1})" }; spf1.Points.Add(new DataPoint(col.FireLoad.MEdx, col.FireLoad.MEdy)); LineSeries sf1 = new LineSeries() { Color = OxyColors.DarkRed, MarkerType = MarkerType.None, StrokeThickness = 1 }; foreach (var p in col.fireMxMyPts) { sf1.Points.Add(new DataPoint(p.X, p.Y)); } colMxMyID.Series.Add(sf1); colMxMyID.Series.Add(spf1); LineSeries spf2 = new LineSeries() { Color = OxyColors.Black, MarkerType = MarkerType.Plus, MarkerSize = 4, MarkerStroke = OxyColors.Black, MarkerFill = OxyColors.Black, MarkerStrokeThickness = 1, LabelFormatString = "fire ({0},{1})" }; spf2.Points.Add(new DataPoint(col.FireLoad.MEdx, -col.FireLoad.P)); LineSeries sf2 = new LineSeries() { Color = OxyColors.DarkBlue, MarkerType = MarkerType.None, StrokeThickness = 1 }; foreach (var p in col.fireMxNPts) { sf2.Points.Add(new DataPoint(p.X, p.Y)); } colMxNID.Series.Add(sf2); colMxNID.Series.Add(spf2); LineSeries spf3 = new LineSeries() { Color = OxyColors.Black, MarkerType = MarkerType.Plus, MarkerSize = 4, MarkerStroke = OxyColors.Black, MarkerFill = OxyColors.Black, MarkerStrokeThickness = 1, LabelFormatString = "fire ({0},{1})" }; spf3.Points.Add(new DataPoint(col.FireLoad.MEdy, -col.FireLoad.P)); LineSeries sf3 = new LineSeries() { Color = OxyColors.DarkGreen, MarkerType = MarkerType.None, StrokeThickness = 1 }; foreach (var p in col.fireMyNPts) { sf3.Points.Add(new DataPoint(p.X, p.Y)); } colMyNID.Series.Add(sf3); colMyNID.Series.Add(spf3); } PlotModel[] plots = new PlotModel[] { colMxMyID, colMxNID, colMyNID }; string[] plotNames = new string[] { "MxMy", "MxN", "MyN" }; for (int i = 0; i < plots.Length; i++) { var pngExporter = new OxyPlot.Wpf.PngExporter { Width = 600, Height = 400, Background = OxyColors.White }; var bitmap = pngExporter.ExportToBitmap(plots[i]); MemoryStream stream = new MemoryStream(); BitmapEncoder encoder = new BmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmap)); encoder.Save(stream); Bitmap bmp = new Bitmap(stream); ImageConverter converter = new ImageConverter(); byte[] output = (byte[])converter.ConvertTo(bmp, typeof(byte[])); string path = System.IO.Path.GetTempPath() + plotNames[i] + ".tmp"; File.WriteAllBytes(path, output); } }
public ResultViewModel(Dictionary <int, double> finalAAV, List <List <List <int> > > awsCount) { // グラフを描画 LastAAVGraphModel.Value = CreateLastAAVGraphModel(finalAAV); AwsCountGraphModel.Value = CreateAwsCountGraphModel(awsCount); // データをバックアップ this.finalAAV = finalAAV; this.awsCount = awsCount; // タイトルバーを設定 TitleStr.Value = SetTitleBar(finalAAV); // コマンドを設定 CopyAAVPictureCommand.Subscribe(_ => { // 制空値のグラフを画像としてクリップボードにコピー var pngExporter = new OxyPlot.Wpf.PngExporter(); var bitmapSource = pngExporter.ExportToBitmap(LastAAVGraphModel.Value); Clipboard.SetImage(bitmapSource); }); CopyAAVTextCommand.Subscribe(_ => { // 制空値の下側確率の情報をテキストとしてクリップボードにコピー double sum1 = 1.0, sum2 = 0.0; var temp = new Dictionary <int, List <double> >(); foreach (var pair in finalAAV.OrderBy((x) => x.Key)) { sum2 += pair.Value; temp[pair.Key] = new List <double> { pair.Value, sum1, sum2 }; sum1 -= pair.Value; } string output = "制空値,確率分布(%),上側確率(%),下側確率(%)\n"; foreach (var record in temp) { output += $"{record.Key},{100.0 * record.Value[0]},{100.0 * record.Value[1]},{100.0 * record.Value[2]}\n"; } Clipboard.SetText(output); }); CopyAwsPictureCommand.Subscribe(_ => { // 制空状況のグラフを画像としてクリップボードにコピー var pngExporter = new OxyPlot.Wpf.PngExporter(); var bitmapSource = pngExporter.ExportToBitmap(AwsCountGraphModel.Value); Clipboard.SetImage(bitmapSource); }); CopyAwsTextCommand.Subscribe(_ => { // 制空状況の詳細をテキストとしてクリップボードにコピー string output = "航空隊,回数,確保(%),優勢(%),均衡(%),劣勢(%),喪失(%)\n"; int loopCount = awsCount[0][0].Sum(); for (int si = 0; si < awsCount.Count; ++si) { for (int ci = 0; ci < awsCount[si].Count; ++ci) { output += $"{si + 1},{ci + 1},"; output += $"{100.0 * awsCount[si][ci][0] / loopCount},"; output += $"{100.0 * awsCount[si][ci][1] / loopCount},"; output += $"{100.0 * awsCount[si][ci][2] / loopCount},"; output += $"{100.0 * awsCount[si][ci][3] / loopCount},"; output += $"{100.0 * awsCount[si][ci][4] / loopCount}\n"; } } Clipboard.SetText(output); }); }