回读图像功能优化

This commit is contained in:
“hsc”
2026-07-30 16:33:32 +08:00
parent f350058f53
commit e90dc805fc
11 changed files with 674 additions and 11 deletions

View File

@@ -24,5 +24,32 @@ namespace CurveModule.Views
{
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}");
}
}
}
}