DrawBitmap support for ICanvas
See original GitHub issueDescription
In terms of drawing using ICanvas I feel features are bit limited on MAUI. Drawing on bitmap would be lot easier to save the UI and reuse object whenever needed.
For example, here is a case where I have tried to render circle based on the touch points interacted and for this I need to store every points and render again for each interaction. This results in performance issues on higher point counts. So I have overcame this issue on android native by drawing the points on bitmap parallelly and rendered the existing bitmap to the view on each interaction. So this lets canvas draw the bitmap alone at invalidate. So it would be good to provide feature to draw on the bitmap and draw a bitmap to the view using ICanvas.
Public API Changes
canvas.DrawBitmap(bitmap)
-Renders bitmap to the given canvascanvas.DrawCircle(bitmap)
-Render on the bitmap object
Intended Use-Case
In my app I have a situation where I would add different paths to the canvas. But adding each paths every time at invalidation costs me the performance issue. Drawing on the bitmap and drawing the same bitmap to the view would be lot performance savings
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:5 (1 by maintainers)
I’ve run into this problem as well. I’d like to just draw to a bitmap and then draw the bitmap to the canvas, but can’t figure out how to do it without platform code. I’m looking at IImage or IPicture instead. I don’t need to read from file, I just need this buffer to exist in memory to save on canvas draw operations.
One other way I’ve thought of doing it is with parallel linq, but the canvas really doesn’t want to be accessed like this. Next step i guess is to clone the canvas for the draw operations, but this is rabbit-hole-ing rather quickly.
The end goal here is to take an array of pixels and blit them to the canvas, but just stumbling my way there. DrawImage() looks like what I want, but not sure how to get that IImage…
here’s my sample: https://github.com/SheepReaper/ParallelDrawOnCanvas flip my comments in DrawableBase to see the broken parallel.
This was inspired by my wanting to do a fully MAUI non-skia version of this: https://swharden.com/blog/2021-09-10-maui-graphics/
So my paths right now, if anyone knows how:
@BharanikhumarSR sorry for the confusion, we now realize this was a feature proposal and not a bug report. You can ignore the comments from the msftbot account - this won’t be closed.