ionic cordova call native API for hardware camera to take pictures

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

Chinese: Http://Www.Ionic.Wang/native_doc-index-id-121.Html

1. Install the plug-cordava

ionic cordova plugin add cordova-plugin-camera
npm install @ionic-native/camera

2. The introduction of the corresponding module registered in app.module.ts

import { Camera} from '@ionic-native/camera/ngx';
    ...
@NgModule({
    ...
    providers: [
        ...
        Camera
        ...
    ]
    ...
})
export class AppModule { }

3. In the document used the page to see the introduction of use

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
});

 

Guess you like

Origin www.cnblogs.com/heweiquan/p/11388603.html