Resize an image down
Using NS 4.0, Core 4.0 and iOS 4.0.1
Plugin version 6.0.1
I'm migrating to 6.0 - and I'd like to size the image down to around 1280 width and keep the aspect ratio before I store it.
` selection.forEach( (selected) => { selected.options = { width: 640, height: 512, keepAspectRatio: true };
imageSourceModule.fromAsset(selected).then((imageSource: imageSourceModule.ImageSource) => {
console.log( imageSource.width + "x" + imageSource.height );
this.save = imageSource.toBase64String("jpeg"); } ); `
The width x height printout seems to be 770x512 - but the file thats returned by base64 is twice the size. 1540 x 1024.
Would this by any chance have to do with device dpi?
This is ios.
I think that the image size is scaled depending on the device. You can check this by accessing the imageSource.ios.scale property and it should return 2 in your case (770 x 2 = 1540).
Thanks...seems to be so.
@erjdriver may I ask why you're saving it as base64? is it less memory intensive? or any other reasons? thanks in advance
Saving as base64 because I wanted to transmit the image to a remote server.
Otherwise it's more memory intensive - storage and computational than straight binary save on the local device.
You can also do a POST in binary format - but...
Thanks!
I wonder why then NS claim this:
"In contrast, when using ImageSource or Base64 encoded string, the Bitmap is transferred to Javascript, so it will be released when Javascript object reclaims. Javascript garbage collection happens less frequently than Java garbage collection which might lead to Out Of Memory."
https://docs.nativescript.org/performance-optimizations/images-optimisations