【问题标题】:how to compress image in ionic 2如何在离子2中压缩图像
【发布时间】:2017-10-01 06:56:19
【问题描述】:

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

非常感谢

【问题讨论】:

    标签: ionic2


    【解决方案1】:

    尝试使用离子相机插件来关注 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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 对我来说似乎 ionic 忽略了我通过它的任何质量......这对你有用吗?
      猜你喜欢
      • 2016-07-17
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      相关资源
      最近更新 更多