question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DrawBitmap support for ICanvas

See original GitHub issue

Description

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 canvas
  • canvas.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:open
  • Created 2 years ago
  • Reactions:7
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
SheepReapercommented, Apr 25, 2022

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:

  • Create an IImage without reading from file, somehow reacting to canvas size changes (not necessary for final solution)
  • Draw on ICanvas in parallel
2reactions
hartezcommented, Mar 4, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SKCanvas.DrawBitmap Method (SkiaSharp)
Draws a bitmap on the canvas.
Read more >
how to draw a Bitmap on the Top Right of the Canvas
in MyView right under Rect bitmapRect; make the variables public int width; public int height;. then in your MyView class put this method...
Read more >
ICanvas
The canvas object is of type ICanvas and derives from ISlideShowObject. It provides the opportunity to draw simple geometric shapes.
Read more >
Getting Started with Android Canvas Drawing
One of the most common drawing operations is to draw a bitmap (image) onto the canvas. The method for doing this is just...
Read more >
Contact us
Our friendly support team is available Monday-Friday from 9:00AM to 5:00PM CST. Topic. General Question, Gift Cards, Issues With My Order / Product ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found