Ionic Framework : @ionic/angular 5.5.2
@angular-devkit/build-angular : 0.1100.7
@angular-devkit/schematics : 10.0.8
@angular/cli : 10.0.8
@ionic/angular-toolkit : 2.3.3
Capacitor:
Capacitor CLI : 2.4.5
@capacitor/core : 2.4.5
Utility:
cordova-res : not installed
native-run : 1.3.0
I've been trying to let the user add images from the camera or gallery using this tutorial
(https://enappd.com/blog/camera-and-image-picker-in-ionic-apps/148/). When I run the application on the emulator, the error message (from ToastController) said 'plugin_not_installed'.
page1.ts
import { Camera, CameraOptions } from "@ionic-native/Camera/ngx";
import { File } from "@ionic-native/file/ngx";
export class Page1 extends OnInit(){
constructor(
private camera: Camera,
private actionSheetController: ActionSheetController,
private file: File
){}
async pickImage(sourceType) {
const options: CameraOptions = {
quality: 100,
sourceType: sourceType,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.PNG,
mediaType: this.camera.MediaType.PICTURE,
};
await this.camera.getPicture(options).then(
(imageData) => {
console.log(imageData);
// imageData is either a base64 encoded string or a file URI
if (imageData !== undefined)
this.img = "data:image/jpeg;base64," + imageData;
},
(err) => {
this.presentToast(err);
}
);
}
async selectImage() {
const actionSheet = await this.actionSheetController.create({
header: "Select Image source",
buttons: [
{
text: "From Gallery",
handler: () => {
this.pickImage(this.camera.PictureSourceType.PHOTOLIBRARY);
},
},
{
text: "From Camera",
handler: () => {
this.pickImage(this.camera.PictureSourceType.CAMERA);
},
},
{
text: "Cancel",
role: "cancel",
},
],
});
return await actionSheet.present();
}
page1.html
<ion-card id="pictureFrame" (click)="selectImage()">
</ion-card>
question from:
https://stackoverflow.com/questions/65830328/ionic-capacitor-camera-file-plugin-not-install 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…