Resizing Image in NativeScript?

Viewed 948

I wan to resize an image in SD card sized 3000*4200 px to 250*250 sized profile picture. I tried so many ways using android BitmapFactory, but nothing worked.

Is there any plugin for this?

3 Answers

You can use the ImageAsset within framework.

import * as imageAssetModule from "tns-core-modules/image-asset/image-asset";


let asset = new imageAssetModule.ImageAsset(yourPicturePath);
asset.options = {
   width: yourWidth,
   height: yourHeight,
   keepAspectRatio: true // Set to false if you do not want aspect ratio
};

Now you can create an ImageSource from the asset then save it file.

ImageSource now supports resize() since @nativescript/core 6.5.9

Basically get your ImageSource and call resize(newSize) on it.

const imgSrc = ImageSource.fromResourceSync('ball');
imgSrc.resize(100);

Here's a video of Alex showing how it works: https://www.youtube.com/watch?v=joXwqCc4JlE

Try to this plugin for image resizing and zoom :-

https://market.nativescript.org/plugins/nativescript-image-zoom
Related