D
D
Daniel2021-01-17 22:31:08
WPF
Daniel, 2021-01-17 22:31:08

How to display graphics in wpf, WHY DOES MY window freeze for 1-2 seconds after any window resizing?

Attempt number 2.
A simple program, the code is below, I draw polygons, then I display it, the problem is that the program window cannot move to the second screen, and any RISIZE of the window freezes for 1-3 seconds, like what kind of crooked WPF, or something I don't know.
Why the window hangs, my assumption is that a redraw is taking place, that is, for some reason , re-executing all drawLines .... Then why, if I transferred an already drawn DrawingVisual component to the picture, or where is the built-in direct buffering.

DrawingVisual visual = new DrawingVisual();
DrawingContext dc = visual.RenderOpen();
 /// dc.Draw ...... рисую полигоны, при 10_000 и более полигонов НАСТУПАЕТ СМЭРТЬ
dc.Close();
DrawingImage di = new DrawingImage(visual.Drawing);
Image image = new Image();
image.Source = di;
Canvas.Children.Add(image);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vasily Bannikov, 2021-01-18
@vabka

1. Draw a picture in a background thread, and display it in the main
2. Do not use System.Drawing - it is slow. Look towards skia
For 3d there is opengl and other special APIs for drawing with a graphics card.

A
Alexander Ananiev, 2021-01-18
@SaNNy32

https://stackoverflow.com/questions/16107877/fast-...
https://social.msdn.microsoft.com/Forums/vstudio/e...

D
Developer, 2021-01-18
@samodum

Time-consuming operations should be done in a separate thread, and not in the UI thread.
Therefore, it freezes.
You risk getting ANR.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question