angular - 如何从 IONIC 3 中的图库中获取或选择图像

标签 angular typescript ionic-framework ionic2 ionic3

如何从 IONIC 3 中的图库中获取图像?

我无法使用

从图库中获取图像

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

https://ionicframework.com/docs/native/camera-preview/

最佳答案

您可以使用 Native camera plugin 来做到这一点.

.ts

 //take Photo
  takePhoto(sourceType:number) {
    const options: CameraOptions = {
      quality: 50,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE,
      correctOrientation: true,
      sourceType:sourceType,
    }

    this.camera.getPicture(options).then((imageData) => {
      let base64Image = 'data:image/jpeg;base64,' + imageData;
    }, (err) => {
      // Handle error
    });
  }

注意:您只需要像这样调用上面的方法:

this.takePhoto(0);//照片库

this.takePhoto(1);//相机

0 for photo library 1 for Camera

用户界面

enter image description here

关于angular - 如何从 IONIC 3 中的图库中获取或选择图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47118760/

相关文章:

typescript - 如何通过 Ionic 4 选项卡按钮传递参数

asp.net - 在没有登录提示的情况下通过 Angular 2 访问 Windows Authenticated Web API

javascript - angular2 rc6 - systemjs.config.js 使用子文件夹/src/app

angular - 在 typescript 中查找键值最小的对象

angular - 在定义 NgModule 时使用外部 JSON 文件的值

angular - Protractor 结果不一致 - 失败 : script timeout: result was not received

javascript - firebase.database 不是函数

node.js - Angular Nodejs : Output is Undefined, 无法从服务器访问数据

TypeScript 编译选项 : module vs target

javascript - 根据当前地理位置 ios 应用程序 javascript 从纬度/经度列表返回值