How Bitmapiamge's Cache Works
I need to add thousands of PNG icons (32x32) to the Canvas, the current method is to add thousands of DrawingVisuals to the Canvas, then iterate through all the DrawingVisuals and call DrawImage on it, each call will create a BitmapImage object.
Then when panning the Canvas with the middle mouse drag, I refresh the positions of all icons.
Originally, this operation was very smooth, until I added a line of code to load the same image resource in the construction method of Canvas, so it would be very stuck when dragging.
As far as I know, BitmapImage will be cached by default, but I don't know the specific caching mechanism. Is the cache checked every time a New BitmapImage is created? If so, how to explain the above stuck phenomenon?
This is normal
This is after adding that line of code
2048 icons on Canvas
Main code:
Constructor: