On IOS, Image-Source expects a number between 0.0 to 1.0 to specify the image quality.
On Android, Image-Source expects a number netween 0 and 100.
It brings up the situation developers have to use a platform-check if the want to get a JPG with 80% quality:
let quality = platformModule.isAndroid ? 80 : 0.8;
return image.toBase64String("jpeg", quality);
I'd suggest to use one scale for both platforms to have an more consistent API.
What do you think?
@madmas sounds legit - I am marking this issue as a "good first issue" so that anyone interested in becoming a NativeScript contributor can make a PR and implement this one.
I am guessing one possible approach would be to change the iOS implementation of toBase64String
where the quality
is passed to getImagedata
which works with the native values (0.0 to 1.0). So a potential fix would be to normalize the value before passing it to getImageData
(e,g, in 'toBase64Striing' receive 80 as quality
and pass 0.8 to getImageData
)
Once this is done we could implement this for saveToFile
as well.
@NickIliev I will like to work on this issue. Any guidance will be really helpful.
@NickIliev Need some help, I followed the Initial Setup and tried to run the Unit tests but every time I am getting this error:
Unable to apply changes on device: ZX1G4247XN. Error is: cp: no such file or directory:/Users/sudhanshu/Documents/Projects/NativeScript/tests/node_modules/tns-android/framework/libs.
I am really interested in getting this done, any help will be appreciated.
Update: I was able to fix the issue. I made the required code changes, I also added few extra unit tests. Most test cases are passing but there is one test case with LABEL module that is falling.
LABEL.test_Set_TextWrap_Native
Also I have been getting these these errors:
W ExifInterface: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
I am still trying to figure out how to fix these, google search also didn't yield any useful information.
If anyone can help me out I will really appreciate it.
Update: I ran the tests on another device and now all the tests are passing. Still getting these errors:
W ExifInterface: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Submitted PR https://github.com/NativeScript/NativeScript/pull/5517