image seismic gather Sorry for my bad English.
I create a visualisation for seismic gathers. Gather contains about 100-300 traces. Each trace (polyline
) contains more then 1000 points.
If I try to add a List<polyline>
to canvas as canvas.Children.Add
i have a trouble. The application spends to much resources.
I found out that one of the key to resolve this problem is using a bitmap (RenderTargetBitmap
). But I can not understand how to avoid render polylines on canvas and immediately export polylines to bitmap and then load to canvas.
xaml
<Canvas x:Name="Canvas_Pic">
</Canvas>
wpf
public void ViewData(Canvas canvas)
{
DrawTraces(canvas);
ConvertToBitmap(canvas);
}
public void DrawTraces(Canvas canvas)
{
List<Polyline> traces = CreatePointsCollection(); // convert double array to polyline list
for (int p = 0; p < traces.Count; p++)
{
traces[p].StrokeThickness = 0.5;
traces[p].Stroke = Brushes.Black;
canvas.Children.Add(traces[p]);
}
}
public void Function(Canvas canvas)
{
Rect bounds = VisualTreeHelper.GetDescendantBounds(canvas);
var rtb = new RenderTargetBitmap((int)canvas.ActualWidth, (int)canvas.ActualHeight, 96,
96, PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(canvas);
dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
}
rtb.Render(dv);
var bitmap = new PngBitmapEncoder() { Frames = { BitmapFrame.Create(rtb) } };
using (var file = File.Create("file.png"))
bitmap.Save(file);
canvas.Children.Clear(); // clear existing polilines
ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri("file.png", UriKind.Relative));
canvas.Background = brush;
}
Also i have a problem with loading bitmap on canvas. I can not create bitmap until canvas not rendered with polylines. That's why i see twice one image: first when polylines drew on canvas and then bitmap each is background of canvas.
How can i optimize it. To make straight bitmap avoid adding polylines to canvas?
With Regards.