nativescript-imagepicker icon indicating copy to clipboard operation
nativescript-imagepicker copied to clipboard

Resize an image down

Open erjdriver opened this issue 8 years ago • 5 comments

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.

erjdriver avatar May 06 '18 14:05 erjdriver

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).

lini avatar May 10 '18 13:05 lini

Thanks...seems to be so.

erjdriver avatar May 11 '18 11:05 erjdriver

@erjdriver may I ask why you're saving it as base64? is it less memory intensive? or any other reasons? thanks in advance

snq avatar Oct 21 '18 15:10 snq

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...

erjdriver avatar Oct 22 '18 13:10 erjdriver

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

snq avatar Oct 22 '18 20:10 snq