3

I am generating a full screen image with 37000 or so markers. To do this I use the following code

 private void DrawMarkers(WriteableBitmap bitmap) { WriteableBitmap marker = BitmapFactory.New(5, 5); var sourceRect = new Rect(0, 0, 5, 5); marker.DrawEllipseCentered(3, 3, 2, 2, Colors.Blue); var s = Stopwatch.StartNew(); foreach (var point in TransformedPoints) { bitmap.Blit(new Rect((int)point.X, (int)point.Y, 5, 5), marker, sourceRect); } s.Stop(); Console.WriteLine("Blitting " + TransformedPoints.Count + " Points took " + s.ElapsedMilliseconds + " ms"); } 

To blit these 37000 points it takes approximately 203 ms on my EliteBook 8770w Windows7. I've gone down from using standard WPF framework elements to drawingVisuals and now to writeable bitmap. I need real time zoom on this set of markers so the markers need redrawing. I would say I need about 50ms for a redraw for it to be ok.

From what I read WriteableBitmap is the lowest level I can go. What is the next step in performance improvement can I go. It seems this needs to be delegated to the GPU. How could I do this in C# or what libraries should I use?

1 Answer 1

3

One big improvement would be to use leverage the BitmapContext concept so you don't lock and unlock all the time and avoid too many pixel copies.

using (marker.GetBitmapContext(ReadWriteMode.ReadOnly)) { using(bitmap.GetContext()) { foreach (var point in TransformedPoints) { bitmap.Blit(new Rect((int)point.X, (int)point.Y, 5, 5), marker, sourceRect); } } } 

And you should provide the BlendMode.None if you don't need alpha blending:

bitmap.Blit(new Rect((int)point.X, (int)point.Y, 5, 5), marker, sourceRect, BlendMode.None); 
  • rene
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.