Draw path in android is not smooth

35 views
Skip to first unread message

Adler

unread,
Nov 7, 2019, 5:42:34 AM11/7/19
to skia-discuss
Hi,

I have an Xamarin.Forms app and I'm using SkiaSharp to paint on a picture,
In Android if I draw fast in circles instead of circles I see triangles. (See attachment)
Can anyone help with it?
1573123215082[1].jpg

Matthew Leibowitz

unread,
Nov 11, 2019, 5:41:28 PM11/11/19
to skia-discuss
This might be a result of several things, but the most common is how you are recording the points.

If you are going really fast, then this is just because you are moving to fast for the device to record all the touch points - this usually only happens if you are really fast on a really low end device.
Another reason might be that you are going to much on the UI thread, so the points are coming in fine, but the delay between each point is just too high. You can make sure that you aren't doing to much by just removing all but the points and lines code.

In you case, you might be doing an expensive operation, such as loading the image. Typically, you would load the image once in a SKImage and then cache that in a field. You should end up with a simple;

void draw() {
    canvas.DrawImage();
    canvas.DrawPath();
}

In most cases, it is just doing a bit too much on the UI thread. Just need to keep in mind that all the drawing logic runs many times a second, and if you are refreshing every touch, you may be rending hundreds of times a second - which will get in the way of the incoming points.

I have a ticking clock that you can draw on. It is not the greatest demo, since I do a bit too much too fast, but you can have a look and see if that helps.

Adler

unread,
Nov 12, 2019, 2:38:54 PM11/12/19
to skia-discuss
Thanks!
I found the problem,
My application crashed few times with an out of memory exception so I added a call to GC.Collect() before drawing the paths,
I removed it and now it works fine.
Thanks for your plugin, I love it!!
Reply all
Reply to author
Forward
0 new messages