ionic以html显示所选图像

时间:2019-05-18 15:08:26

标签: ionic-framework

我正在使用图像选择器拾取图像并将其存储在Firebase中。我想在html中显示图像如何在html中显示图像?

pickImageFromGallery() {

this.imagePicker.getPictures({ maximumImagesCount: 1, outputType: 1 }).then((res) => {
  if (res) {
    if (res.length > 0) {
      debugger;
      this.helper.load();
      const image = `data:image/jpeg;base64,${res}`;
      let id=Date.now();
      const pictures = this.storage.ref('deal/' + id);
      pictures.putString(image, 'data_url').then(r => {
        r.ref.getDownloadURL().then(r => {
          this.deal = r
          this.helper.dismiss();
          this.helper.toast('Uploaded');

        });
      }, err => {
        this.helper.dismiss();
        console.log(err);
      });
    } else {
      this.helper.toast('you didnt selected any image from the gallary');
      this.helper.dismiss();
    }

  } else {
    this.helper.toast('you didnt selected any image from the gallary');
    this.helper.dismiss();
  }
  //this.user.photo='data:image/jpeg;base64,'+res;


}, (err) => {
  console.log('failed to get images from gallery');

});
 }

与代码中一样,imgage URL正在保存在this.deal中。我也尝试这样显示

  <ion-img (click)="setImage()" style="width:120px;height:120px"  [src]="deal ||  'https://cdn.dribbble.com/users/21845/screenshots/3938419/placeholder.png'" height="120px"></ion-img>

0 个答案:

没有答案