How to resize image in Ionic 3 without quality reduce and target width and height?

ε祈祈猫儿з 提交于 2019-12-04 19:36:07

Use these options from the Cordova plugin:

targetWidth: Width in pixels to scale image. Must be used with targetHeight. Aspect ratio is maintained. (Number)

targetHeight: Height in pixels to scale image. Must be used with targetWidth. Aspect ratio is maintained. (Number)

Like this

var options = {
      quality: 100,
      sourceType: sourceType,
      saveToPhotoAlbum: false,
      correctOrientation: true,
      destinationType: this.camera.DestinationType.DATA_URL,
      targetWidth: 400,
      targetHeight: 400,
    };

// Get the data of an image
this.camera.getPicture(options).then((imageData) => {
//use the imageData as required.
}, (err) => {

}).catch((error) => {

  })

I use image resizer native API in camera and it works. when value assign for width and height it turn greater one to the target value and adjust another one by original ratio.. here is my code:

 this.camera.getPicture({
  destinationType: this.camera.DestinationType.FILE_URI,
  sourceType: sourceType,
  mediaType: this.camera.MediaType.PICTURE,
  encodingType: this.camera.EncodingType.JPEG,
  saveToPhotoAlbum: (source === PictureSource.CAMERA),
  allowEdit: true
})
  .then(imageUri => {
    this.imageResizer.resize({
      uri: imageUri,
      quality: 60,
      width: 1280,
      height: 1280
    }).then(uri => handler(uri))
  })
  .catch(error => console.warn(error))

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!