如何在Ionic 3中调整图像大小而又不降低质量和目标宽度和高度? [英] How to resize image in Ionic 3 without quality reduce and target width and height?

查看:275
本文介绍了如何在Ionic 3中调整图像大小而又不降低质量和目标宽度和高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想减小相机API拍摄的图像的尺寸,但质量降低不好。最好的办法是降低分辨率,但我不想对所有图像都使用目标宽度和高度。

I want to reduce the size of images taken by camera API but quality reduce is not good. The best thing is to reduce resolution but I don't want to use target width and height for all images.

例如,我希望图像宽度为1280,图像高度根据其比率自动更改,但是在API中,我应该使用确切的宽度和高度。

For example, I want image width be 1280 and image height change automatically by its ratio, but in API I should use exact width and height.

如何通过图像比例更改高度动态?

How can I change height dynamic by image ratio???

现在,我使用以下代码:

For now, I use this code:

 this.camera.getPicture({
  quality: 60,
  destinationType: this.camera.DestinationType.FILE_URI,
  sourceType: sourceType,
  mediaType: this.camera.MediaType.PICTURE,
  targetWidth: 1280,
  targetHeight: 1280,
  encodingType: this.camera.EncodingType.JPEG,
  saveToPhotoAlbum: (source === PictureSource.CAMERA),
  allowEdit: true
})


推荐答案

我在相机中使用图像缩放器本机API,并且可以正常工作。当为宽度和高度分配值时,它会将一个更大的值转换为目标值,然后按原始比例调整另一个值。.
这是我的代码:

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

}

这篇关于如何在Ionic 3中调整图像大小而又不降低质量和目标宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆