Hello, I am encountering issues with dynamically drawing images in the viewport using a DisplayConduit
.
My goal is to display an OpenStreetMap or Google Satellite Map in the viewport dynamically.
The map is divided into several images (called tiles) that are requested from the tile server via a REST API.
I draw each tile (256x256px) in a DisplayConduit.DrawForeground
using the DisplayPipeline.DrawSprite
function.
All downloaded images are stored in memory; I never have more than 100 tiles in memory to display the map in full screen.
When I use GDI+, I can successfully draw the images dynamically, keeping about a hundred System.Drawing.Graphics
objects open to redraw the tiles. This incurs a slight memory overhead, but it works without leaks or memory corruption.
My issues arise when I need to encapsulate the images (System.Drawing.Bitmap
) in a Rhino.Display.DisplayBitmap
to use the DisplayPipeline.DrawSprite
function.
The DisplayBitmap
seems to perform a copy of the image at the time the class is created, therefore any modifications made to the image (System.Drawing.Bitmap
) are not reflected in the DisplayBitmap
.
In the following video, you can see that the zoom level (the last digit of each tile: 12, 13, or 14) that should change each time the map is zoomed in or out remains the same and corresponds to the zoom level at which the DisplayBitmap
was created.
I have tried recreating a new DisplayBitmap
on each render pass, but Rhino hangs with a considerable spike on one CPU core. I have tried to clean up the memory properly using DisplayBitmap.Dispose
and even force the garbage collector with GC.Collect
, but the result is the same.
The question is, how can I dynamically update a DisplayBitmap
?
jmv