首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ionic 2中压缩图像

如何在ionic 2中压缩图像
EN

Stack Overflow用户
提问于 2017-05-03 20:31:02
回答 2查看 2.3K关注 0票数 2

我实际上是实现了一个功能,允许用户上传的照片从手机。有没有值得推荐的图片压缩插件/库?注意:它是图像压缩,而不是图像大小调整。

非常感谢

EN

回答 2

Stack Overflow用户

发布于 2017-05-03 21:23:10

Use the Ionic Native Camera function

有一个从0到100的质量选项。它将返回一个压缩的图像

代码语言:javascript
复制
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
});

票数 2
EN

Stack Overflow用户

发布于 2019-09-05 21:42:22

尝试使用ionic camera插件跟踪CameraOptions。

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43760112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档