WPF - Slow performance when recreate and draw very big bitmap frequently

612 Views Asked by At

In my application, whenever the user moves the mouse around, I have to re-create a new Bitmap with very high resolution ( It may reaches 3000 pixels x 3000 pixels at its biggest size). The size of the bitmap depends on where the mouse is. For example: the size is smallest when the mouse is on the top-left corner of the screen and is biggest when the mouse is on the bottom-right corner.

enter image description here

The problem is when the mouse is very far away from top-left corner, the size of the bitmap is very big. I checked and realize the time of re-creating and drawing bitmap by DrawingContext in OnRender is fine. However there may be a bottleneck in the framework, it takes long time to transfer the drawing data in DrawingContext to the screen. And this influences WPF mouse input system, so the next mouse move event is fired very late and my application becomes laggy. Here is another question on this site that is related to my problem: The reason behind slow performance in WPF

Do you have any idea to solve my problem?

PS: Whenever the user moves the mouse, I create a new bitmap and draw something on it, then call InvalidateVisual() and draw the bitmap into DrawingContext.

0

There are 0 best solutions below