Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skPaint.setColor throws an error if you pass array of numbers to Skia.Color #2113

Closed
mobily opened this issue Jan 4, 2024 · 2 comments · May be fixed by #2144
Closed

skPaint.setColor throws an error if you pass array of numbers to Skia.Color #2113

mobily opened this issue Jan 4, 2024 · 2 comments · May be fixed by #2144
Labels
bug Something isn't working

Comments

@mobily
Copy link

mobily commented Jan 4, 2024

Description

Hello! Thank you for this library, I'm having so much fun using it :)

Passing RGBA values to Skia.Color, for example Skia.Color([0, 128, 0, 255]) throws the following error:

CleanShot 2024-01-04 at 11 31 52@2x

I know I can use Float32Array and 0-1 scale:

const skColor = Skia.Color(Float32Array.from([0, 0.9, 0, 1]))
skPaint.setColor(skColor)

However, the Color type suggests I can pass number[] too. I would be grateful for clarification here 🙏

Version

0.1.231

Steps to reproduce

const skPaint = Skia.Paint()
const skColor = Skia.Color([0, 128, 0, 255])

skPaint.setColor(skColor)

Snack, code example, screenshot, or link to a repository

⬆️

@mobily mobily added the bug Something isn't working label Jan 4, 2024
@louix
Copy link
Contributor

louix commented Jan 16, 2024

tl;dr: you can only use number (e.g. 0xff0000ff), string, or Float32Array.

In JsiSkColor::createCtor, if argument[0].isObject() (true for both Array and Float32Array), it's returned as the color value.

Then when it comes time to turn the jsi::Value to an SkColor in JsiSkColor::FromValue, it tries to get the .buffer property from the object (which is of course is not there on an array -- thus undefined).

@mobily
Copy link
Author

mobily commented Jan 16, 2024

thanks @louix for the clarification, that makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants