Use the device camera

Asked

Viewed 45 times

0

I would like to use the device camera but I’m finding it difficult

In my file list.ts is just:

import { Camera, CameraOptions } from '@ionic-native/camera/ngx';

constructor(public navCtrl: NavController, 
              public navParams: NavParams,
              public http: Http,
              public toastCtrl: ToastController,
              public camera: Camera) {

  }

getFoto(){
    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;
        this.beer.img = base64Image;
       }, (err) => {
        console.log(err);

       });
  }

I also imported in app.module in the preview

import { Camera } from '@ionic-native/camera/ngx';

...

providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    Camera
  ]

Following this documentation, but gave this problem here:

inserir a descrição da imagem aqui

How can I solve?

Here is my project in git.

  • Hey, try looking at this topic: https://answall.com/questions/91242/abrir-camera-dentro-de-umadiv-ionic, if you do not have access to documentation regarding your question: https://ionicframework.com/docs/native/camera/

  • Yeah. With the documentation did not solve and this other is in angular 1 right?

  • says the tags it is in Ionic.

  • but Ionic uses angular and angular of that is not 4

1 answer

0


I was able to solve it this way:

To use the normal camera in Ionic 3 you need to run the following commands If you already have in package.json a plugin with version 5, delete

1. ionic cordova plugin add cordova-plugin-camera 
2. npm install @ionic-native/[email protected] 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.