官网:https://ionicframework.com/docs/native/camera 中文:http://www.ionic.wang/native_doc-index-id-121.html 1.安装cordava插件 ionic cordova plugin add cordova-plugin-cameranpm install @ionic-native/camera 2.在 app.module.ts 中引
官网:https://ionicframework.com/docs/native/camera
中文:http://www.ionic.wang/native_doc-index-id-121.html
1.安装cordava插件
ionic cordova plugin add cordova-plugin-camera npm install @ionic-native/camera
2.在 app.module.ts 中引入注册相应模块
import { Camera} from ‘@ionic-native/camera/ngx‘; ... @NgModule({ ... providers: [ ... Camera ... ] ... }) export class AppModule { }
3.在用到的页面引入看文档使用
import { Camera, CameraOptions } from ‘@ionic-native/camera/ngx‘; constructor(private camera: Camera) { } ... const options: CameraOptions = { quality: 100, 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 });