【问题标题】:Resize and compress image quality before upload in Firebase with Angular在使用 Angular 上传到 Firebase 之前调整图像大小并压缩图像质量
【发布时间】:2018-09-11 16:13:53
【问题描述】:

在我的应用中,用户可以提交将上传到 Firebase 存储的照片。我需要调整大小并压缩照片质量(不破坏它)以不占用存储空间并加快上传和检索过程。

我该怎么办?建议?

这是我的selectPhoto.ts 代码,用于选择我要上传的照片!

selectPhoto_phone(){
    this.camera.getPicture({
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY, 
      destinationType: this.camera.DestinationType.DATA_URL,
      quality: 100,
      encodingType: this.camera.EncodingType.PNG,
    }).then(imageData => {

      this.isEnabled = true;
      this.myPhoto = imageData;
    }, error => {

      this.isEnabled = false;
      console.log("ERROR -> " + JSON.stringify(error));
    });
  }

【问题讨论】:

标签: angular image typescript


【解决方案1】:

使用https://ionicframework.com/docs/native/camera/

有一个 quality 选项,期望值为 0-100,默认值为 50,这将提供压缩图像。

const options: CameraOptions = {
  quality: 40, //change this value
  destinationType: this.camera.DestinationType.FILE_URI,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE
}

this.camera.getPicture(options).then((imageData) => {
 // imageData is either a base64 encoded string or a file URI
 // If it's base64 (DATA_URL):
 let base64Image = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
 // Handle error
});

希望对你有帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 2018-03-14
    • 2021-01-03
    • 2016-09-30
    • 2021-11-14
    • 2021-12-09
    • 1970-01-01
    相关资源
    最近更新 更多