c# - Visualising multi-layer image in WPF -
my data structure has 2 fields:
* backgroundimage (of type bitmap/image) * points (of type point2d []) my use case follows: user can load image app. after image appears on user's screen, might add points (by clicking mouse button). points should visualized on top of image, user should albe reposition them if needed (e.g. drag'n'drop).
at moment solve problem doing following every time user adds / moves point: * clone backgroundimage * draw points on cloned image (using system.drawing.graphics) * return cloned image points (expose property , bind image in wpf).
the time performance of solution ok, consumes lot of memory, everytime end copying whole image. i'm wondering if there's better way of doing (e.g. using layers - backgroundimage remains same time while keep modifying top layer).
my code quite long, if it's needed let me know , i'll post it.
when comes memory consumption, there nothing wrong aproach described long make sure old instances of image not rooted anymore gc can remove them.
however, during timespans in cloned image modified, occupation of memory might of course double lowest possible value when not cloning. reduce memory consumption, movable points can implemented using uielements. keeping implementation simpler using wpf hittesting "drag'n'drop" part. since uielements require more memory points in bitmapimage, actual savings depend on ratio of points in bitmapimage movable points.
to implement points using uielements, place bitmapimage canvas in panel. use canvas container points , set positions using attached properties canvas.top , canvas.left. make points appear in front of bitmapimage, set panel.zindex of canvas.
but if seeing unreasonable memory consumption, should use memory profiler take closer @ parts of process taking space.
Comments
Post a Comment