【发布时间】:2017-10-01 06:56:19
【问题描述】:
我实际上是在实现一个允许用户从手机上传照片的功能。 有没有推荐的图像压缩插件/库? 注意:是图片压缩,不是图片大小调整。
非常感谢
【问题讨论】:
标签: ionic2
我实际上是在实现一个允许用户从手机上传照片的功能。 有没有推荐的图像压缩插件/库? 注意:是图片压缩,不是图片大小调整。
非常感谢
【问题讨论】:
标签: ionic2
尝试使用离子相机插件来关注 CameraOptions。
const options: CameraOptions = {
quality: 20,
targetWidth: 600,
targetHeight: 600,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.PNG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true //may not work with some deices
}
正是 targetHeight 和 targetWidth 发挥了作用。 :)
答案来自:Ionic image compress
【讨论】:
Use the Ionic Native Camera function
有一个从 0 到 100 的质量选项。它将返回一个压缩图像
const options: CameraOptions = {
quality: 50, // Try changing this
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
let base64Image = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
// Handle error
});
【讨论】: