回读图像功能优化
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user