ionic cordova plugin add cordova-plugin-camera
npm install --save @ionic-native/camera
import { Camera, CameraOptions } from '@ionic-native/camera';
/**
* 原生相机
*/
@Injectable()
export class CameraProvider {
constructor(public http: HttpClient, private camera: Camera) {
}
/**
* 调起相机
*/
cameraClick():Promise<any>{
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
return new Promise((resolve, reject) => {
this.camera.getPicture(options).then((imageData) => {
resolve('data:image/jpeg;base64,' + imageData);
}, (err) => {
reject(err)
});
});
}
}
相机返回的是base64