0

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.

  • You may want to take a look at the [WriteableBitmapEx](https://github.com/reneschulte/WriteableBitmapEx) library. – Clemens Feb 20 '20 at 09:38
  • See following : https://stackoverflow.com/questions/4013725/converting-a-canvas-into-bitmap-image-in-android – jdweng Feb 20 '20 at 09:41
  • Is this meant to be a seismometer display, i.e. a bunch of vertically separated curves moving from right to left? If all curves get a single new value cyclically, you may perhaps just move the bitmap raster by 1 pixel per cycle, and a new pixel column with the new data. – Clemens Feb 20 '20 at 09:45
  • @jdweng No, that's Android. – Clemens Feb 20 '20 at 09:46
  • But still some solution would apply by using a smaller bit size would reduce the processing time. – jdweng Feb 20 '20 at 10:07
  • @Clemens It is vertical curves (traces) combined in ensemble. App read the file (that contains curves) and draw their all on canvas. – Eugenii Zoub Feb 20 '20 at 13:01
  • And it's only done once, i.e. no cyclic update? – Clemens Feb 20 '20 at 13:27
  • I add the image of seismic gather. Readed file filling the double array (contains all traces), then array must be drawn on canvas at once. Also i noticed that i can not do bitmap without render on canvas i.e. avoid adding to child. It works like screenshot. May be there is some approaches to get bitmap based on polylines not canvas. But there is another problem that i have list of polylines not one polyline. – Eugenii Zoub Feb 21 '20 at 08:33

0 Answers0