Any examples of using a virtual canvas with SkiaSharp? #2197
Replies: 4 comments 1 reply
-
I do not know of a control off hand, but this is something that is certainly an idea that I am interested in. I actually played around with this before: mono/SkiaSharp.Extended#79 That PR is ancient but I borrowed ideas and code from mapsui: https://github.com/Mapsui/Mapsui This type of feature really is a great idea because it will help reduce the bad practice I have seen of people creating massive canvases in memory. Maybe my pr was let down by my poor skills in getting all the pan, rotate, scale, I could clean up the PR and then someone who knows more can fix the gestures part. But, I think the drawing part is working currently, the gestures let me down. But, can't be sure as that was a long time ago. |
Beta Was this translation helpful? Give feedback.
-
Thanks @mattleibow,
Agree it would be a great feature.
Was just scanning the PR. I suspect we don't need any gesture support, or touch support for that matter. We'd be passing the gestures to the underlying map control for 'that' control to pan and zoom. We will just read the results of that panning and zooming, then adjust the SkiaSharp canvas to the desired zoom/position for a re-draw. So, we need less of the advanced gesturing stuff, and more of the virtual canvas stuff. If you could point us more towards the virual canvas portion of the implementation, that would be great. Any help is much appreciated. Thank you @mattleibow ! |
Beta Was this translation helpful? Give feedback.
-
@mattleibow we're looking to do this in Blazor BTW. :) I've been trying to reverse engineer how the PR works, as I expected to see some type of virtual canvas class, but a virtual canvas implementation I somewhat expected to find in "SKDynamicSurfaceView.cs" doesn't have much in it. I'm also not sure what we're getting based on the derivation of "Layout [View]" and if that's specific to Xamarin Forms or SkiaSharp. Anyway, we can always keep things extremely simple for now, and ask for the virtual canvas beahvior? |
Beta Was this translation helpful? Give feedback.
-
I'll chime in here, my main goal is this. I have a stock image which is my world map bitmap. I have one I have a secondary Tracking the cursor radar more or less is working thus far. Panning more or less there but the underlying bitmap does not track well with the mouse, especially when I try to achieve an appropraite scale. So I feel as though this must stay in canvas coordinates, not world, or even scaled. Having some difficult getting the zoom to work correctly in a way that feels natural, bounces around and such; and bounds checking not done yet. It sort of works, but zooming to cursor, for the aforementioned concerns, feels like kind of a kludge. As far as I can determine, I have at least three main scaling factors, not including the actual zoom component (four). First, survey canvas to world bitmap dim (square, i.e. Approaching in WPF, and most of the view, view model plumbing is there. Unfortunately is not easy to distill out an MVP to show, receive feedback, but I am happy to work with the conversation here best I can manage. Otherwise, let me know, I can join a discord or something, present some material, gain some feedback that way, if it would be helpful to visualize, review code, etc. Happy to offer that as well. Fortunately, though, it seems as though as long as the source geometry is tracking to the bitmaps, then it seems very easy to set canvas scale, translate, etc. So kudos there. And for future thought, the idea of tiling my source map, not lost on me either. And is something I might possibly need to consider anyway, for a lot of reasons, world coordinate precision, accurate overlays, and so on, being among them. But not before I get the basics more or less sorted through. Any pointers, insights, pro tips, would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
Hello @mattleibow!
Are you aware of any code or samples that leverage a virtual canvas with SkiaSharp? The use case we're trying to solve is something like the following:
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions