mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.4k stars 537 forks source link

Can Skiasharp be used for Inking Scalable drawings #649

Closed Ponant closed 5 years ago

Ponant commented 5 years ago

Hi, I currently have a uwp app which uses the InkCanvas from UWP combined with Win2D.

In this way the user can draw with pen or touch input. The drawings are scalable like SVG. I cannot port this UWP to Xamarin because InkCanvas is not recognized by Xamarin, so I wonder if I can convert my code to use Skiasharp. Hence my question: Does Skiasharp supports pen input for vector graphics to be drawnd directly on their tablets? Thank you for your advice it will surely help.

mattleibow commented 5 years ago

Right now there is a fair bit of support with the touch events, but I have not done any testing with the various pens, such as the S-Pen or the iOS Pencil. YOu can check out the SkiaSharp.Views and/or SkiaSharp.Views.Forms packages with native view support.

If you are just wanting to capture signatures, or something similar, there is the SignaturePad (https://github.com/xamarin/SignaturePad)

If anyone has a device with a pen and wants to give it a go and send some feedback or PR with more detailed "pen" events, then I will gladly integrate it into the core library.

mattleibow commented 5 years ago

For making things scalable, that is very simple - just capture everything in a SKPath with a few line-tos and curves. In fact, you could probably have a look at what is happening in the Android version of signature pad, as the paths are actually very similar since Android uses Skia under the hood.

https://github.com/xamarin/SignaturePad/blob/master/src/SignaturePad.Android/InkPresenter.cs https://github.com/xamarin/SignaturePad/blob/master/src/SignaturePad.InkPresenter.Shared/InkPresenter.cs

Ponant commented 5 years ago

@mattleibow , thanks for the feedback. For your question, I have the following devices: Surface pro (2014-2015 model) Windows 10 Pro Thinkpad Yoga Windows 10 Pro iPad Pro with its pen I should be able to get an android-based pen device, but for later. I am happy to send to you any events that maybe needed.

Here is my take on the windows Ink API and what features i really need. The app is designed for writing (like OneNote), so I go beyond signatures but I do not need fancy stuff, in order of priority first: -FitToCurve, i.e. the device API takes your raw pen data and turns them into cubic Bézier curves -Pressure sensitivity, but I can do without that for a first shot -The API needs to be able to give me back the bezier curve such that I transform these data

Notice that the bezier curves typically hugely reduce the number of data needed. The raw data are just too numerous in the windows ink api.

Technically it works as such: -You create an InkCanvas in XAML and set your pen mode to pen only, for instance, and FitToCurve to true (default). Assume that you set Pressure Sensitivity to false, to make it simpler.

-You draw and retrieve the ink with InkPresenter.StrokeContainer.GetStrokes(). These strokes have the attributes, such as color, width, height, matrix transform, and also the data points for each stroke. If FitToCurve is to true, then you get the bezier points, which are only cubic beziers. If you set FitToCurve to false, then you get only the raw data. The FitToCurve is crucial to me as I am circulating the data around the web (hence I need light-weight data).

Is this scenario possible according to you and if so can you draw some advice on the api needed? I never tried SkiaSharp so I fear I can loose myself in details as I read through the various docs.

mattleibow commented 5 years ago

I am closing this as your question is better discussed on the forums (https://forums.xamarin.com/) or on SO.