【问题标题】:ionic 3 image picker & preview like instagramionic 3 图像选择器和预览,如 instagram
【发布时间】:2023-03-14 09:47:01
【问题描述】:

我正在开发一个像 instagram 这样的 ionic 3 应用程序,让用户可以从他们的手机相册中挑选照片,同时他们可以在同一页面上预览照片。

我尝试过 cordova-plugin-photo-library here,但没有限制功能,所以我必须从用户相册中获取所有照片,这可能是非常大的容量。用户必须等到所有照片都加载完毕后才能单击并选择一张照片。这真是糟糕的用户体验。

有人有想法吗?谢谢。

【问题讨论】:

  • 你找到解决这个问题的方法了吗?

标签: image cordova ionic-framework photo


【解决方案1】:

你可以使用base64图像

 # view 
 <img *ngFor='let image of images' [src]="DomSanitizer.bypassSecurityTrustUrl('data:image/jpeg;base64,'+image)" style="width: 100px;height:100px;" [hidden]="lastImage === null">

 # choice select method
 public presentActionSheet() {
    let actionSheet = this.actionSheetCtrl.create({
      title: 'choice select method',
      buttons: [
        {
          text: 'gallery',
          handler: () => {
            this.takePicture(this.camera.PictureSourceType.SAVEDPHOTOALBUM);
          }
        },
        {
          text: 'take image',
          handler: () => {
            this.takePicture(this.camera.PictureSourceType.CAMERA);
          }
        },
        {
          text: 'cancel',
          role: 'cancel'
        }
      ]
    });
    actionSheet.present();
  }



  public takePicture(sourceType) {
  // Create options for the Camera Dialog
  var options = {
    quality: 100,
    sourceType: sourceType,
    encodingType: this.camera.EncodingType.JPEG,
    allowEdit: true,
    saveToPhotoAlbum: true,
    targetWidth: 600,
    targetHeight: 600,
    correctOrientation: true,
    destinationType: this.camera.DestinationType.DATA_URL
  };

  // Get the data of an image
  this.camera.getPicture(options).then((imagePath) => {
    // Special handling for Android library
    if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.SAVEDPHOTOALBUM) {
this.images.push(imagePath);



    } else {
      this.images.push(imagePath);


    }
  }, (err) => {
    this.presentToast('Error while selecting image.');
  });

}

【讨论】:

  • 他的问题是关于限制要拉入的照片数量。例如查询选择器:顶部和跳过。
  • 感谢 mohammad mahmoodi,但此解决方案不允许我通过在用户选择图片时添加实时预览框来更改 UI(就像 Instagram 一样)。或者您知道如何实现这一目标?
  • @pezetter 没错。有任何想法吗?谢谢。
猜你喜欢
  • 2019-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-17
  • 2018-06-11
  • 2019-12-20
  • 2015-01-23
  • 2011-11-16
相关资源
最近更新 更多