nativescript-community / ui-canvas

Implement Canvas into your NativeScript apps.
https://nativescript-community.github.io/ui-canvas/
Apache License 2.0
31 stars 9 forks source link

[Question] Is there support for tiling images? #8

Closed wafs closed 4 years ago

wafs commented 4 years ago

I checked the demos and have had a play with this canvas library, but couldn't find the correct area to set the image mode to tiling when using an image to fill a path.

// How do I get image to repeat x/y ? 
canvas.drawBitmap(image , 0, 0, paint);

Is this a thing?

farfromrefug commented 4 years ago

@wafs not sure that possible. Can you android into android here. If there is a way to do it i'll implement it on iOS and Android

wafs commented 4 years ago

@wafs not sure that possible. Can you android into android here. If there is a way to do it i'll implement it on iOS and Android

There is a way in android by using a shader and then using that shader on the Paint object ( https://developer.android.com/reference/android/graphics/BitmapShader )

But I also achieved the same effect by just looping and drawing the bitmap at the new coordinates every loop. The main reason I asked was because in HTML5's canvas spec it's easy to create a pattern with repeat x/y ( https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createPattern#Creating_a_simple_pattern ) and was wondering if there was a similar API here.

farfromrefug commented 4 years ago

@wafs your solution works but is not optimized. Doing it with a shader is really a lot faster!