nativescript-toolbox
nativescript-toolbox copied to clipboard
nativescript-bitmap-factory crop() API throws error on iOS
In my project, I use the nativescript-bitmap-factory (version 1,8.1) to crop an image:
public cropImage(image : ImageSource) : ImageSource {
let mutable = BitmapFactory.makeMutable(image);
return BitmapFactory.asBitmap(mutable).dispose((bmp) => {
let croppedImage = bmp.crop({x:10,y:10}, {width:300,height:300});
console.log("Image cropped!")
return croppedImage.toImageSource();
});
}
This works beautifully on Android emulators and devices, but throws the following exception on iPhone:
CONSOLE ERROR file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:676:30: Unhandled Promise rejection: The method setNativeSource() expects UIImage instance. ; Zone:
Googled the error message found this:
https://github.com/mkloubert/nativescript-bitmap-factory/issues/19
but there is no solution there.
Is there a fix? Thanks!
Replace in BitmapFactory.ios.js at crop function section:
from
return UIImage(imageRef);
to
return UIImage.alloc().initWithCGImage(imageRef);