Reputation: 401
A code sample would be nice, but just some generic advice on the best way to handle this situation would suffice.
I'm rendering an image on a Win2D Canvas. The image is first made up of piecing together tile bitmaps to form a large image. I'll call that the "Base Image".
I am then using various "draw" calls to mark up the base image and I'm also placing other bitmaps over the base image, to create the final image.
The user can scroll the image in any direction and/or zoom in and out of the image. Mouse movements are tracked and tooltip-like is displayed over the canvas to provide the user with detailed information. Each time the user does anything that affects the image, I'm redrawing the entire image. In some cases, the base image is made up of as many as 46,000 tiny bitmaps.
Even using this heavy-handed approach, the image redraws itself pretty quickly but this feels like the worst possible way of doing it.
My gut tells me that I should render the base image once, keep in it memory and then copy it onto the canvas as needed. After that, overlay the necessary bits to finish the image. I can't find any material that suggests how to keep an in-memory bitmap for this purpose. Nor do I know if that is the most appropriate approach.
Any guidance or suggestions on the most appropriate course of action would be appreciated.
Paul
Upvotes: 1
Views: 1054
Reputation: 264
Your instincts are quite right here - you can most likely get a huge performance increase by drawing the image just once and then reusing a cached version of it.
CanvasRenderTarget is the way to go about this: check out https://microsoft.github.io/Win2D/html/T_Microsoft_Graphics_Canvas_CanvasRenderTarget.htm and https://microsoft.github.io/Win2D/html/Offscreen.htm as starting points.
Upvotes: 2