Open pyou10622 opened 5 years ago
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: ; Task: Promise.then ; Value: Error: The method setNativeSource() expects UIImage instance. setNativeSource@file:///app/tns_modules/tns-core-modules/image-source/image-source.js:112:28 [angular] toImageSource@file:///app/tns_modules/nativescript-bitmap-factory/BitmapFactory.commons.js:374:31 [angular] dispose@file:///app/tns_modules/nativescript-bitmap-factory/BitmapFactory.commons.js:87:30 [angular] ...... onInvoke@file:///app/tns_modules/@angular/core/bundles/core.umd.js:17344:43 [angular] file:///app/pages/capture-image/capture-image.component.js:64:30 [] file:///app/tns_modules/nativescript\M-b\M^@\M-&
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);
In my project, I use the nativescript-bitmap-factory (version 1,8.1) to crop an image:
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: ; Task: Promise.then ; Value: Error: The method setNativeSource() expects UIImage instance. setNativeSource@file:///app/tns_modules/tns-core-modules/image-source/image-source.js:112:28 [angular]
toImageSource@file:///app/tns_modules/nativescript-bitmap-factory/BitmapFactory.commons.js:374:31 [angular]
dispose@file:///app/tns_modules/nativescript-bitmap-factory/BitmapFactory.commons.js:87:30 [angular]
......
onInvoke@file:///app/tns_modules/@angular/core/bundles/core.umd.js:17344:43 [angular]
file:///app/pages/capture-image/capture-image.component.js:64:30 []
file:///app/tns_modules/nativescript\M-b\M^@\M-&
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!