56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace CurveModule.Views
|
|
{
|
|
/// <summary>
|
|
/// CurveRecallView.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class CurveRecallView : UserControl
|
|
{
|
|
public CurveRecallView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DrawingVisual drawingVisual = new DrawingVisual();
|
|
using (DrawingContext context = drawingVisual.RenderOpen())
|
|
{
|
|
VisualBrush brush = new VisualBrush(Chart) { Stretch = Stretch.None };
|
|
context.DrawRectangle(brush, null, new Rect(0, 0, Chart.ActualWidth, Chart.ActualHeight));
|
|
context.Close();
|
|
}
|
|
RenderTargetBitmap targetBitmap = new RenderTargetBitmap((int)Chart.ActualWidth, (int)Chart.ActualHeight, 96d, 96d, PixelFormats.Default);
|
|
targetBitmap.Render(drawingVisual);
|
|
PngBitmapEncoder saveEncoder = new PngBitmapEncoder();
|
|
saveEncoder.Frames.Add(BitmapFrame.Create(targetBitmap));
|
|
string tempFile = @$"D:\ACP\图片\{DateTime.Now:yyyyMMdd_HHmmss}.png";
|
|
System.IO.FileStream fs = System.IO.File.Open(tempFile, System.IO.FileMode.OpenOrCreate);
|
|
saveEncoder.Save(fs);
|
|
fs.Close();
|
|
MessageBox.Show($"导出图片成功");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"导出图片失败:{ex.Message}");
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|