I setup the camera like the docs but it does not display on send to back despite when i refresh it loads the camera full window size and then disappears from page again. What should i do? anybody can help me out on this please.
import { Component, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { CameraPreview, CameraPreviewPictureOptions, CameraPreviewOptions, CameraPreviewDimensions } from '@ionic-native/camera-preview';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage implements AfterViewInit {
pictureOpts: any;
picture: string;
@ViewChild('canvas') objCanvas: ElementRef
constructor(public navCtrl: NavController, private platform:Platform, private cameraPreview: CameraPreview) {
const cameraPreviewOpts: CameraPreviewOptions = {
x: 0,
y: 0,
width: window.innerWidth,
height: window.innerHeight,
camera: 'rear',
tapPhoto: false,
previewDrag: false,
toBack: true,
alpha: 1
};
// start camera
this.cameraPreview.startCamera(cameraPreviewOpts).then(
(res) => {
console.log(res)
},
(err) => {
console.log(err)
});
}
ngAfterViewInit(){
}
onPlay() {
console.log('play');
const pictureOpts: CameraPreviewPictureOptions = {
width: 1280,
height: 1280,
quality: 85
}
// take a picture
this.cameraPreview.takePicture(this.pictureOpts).then((imageData) => {
this.picture = 'data:image/jpeg;base64,' + imageData;
console.log(this.picture)
}, (err) => {
console.log(err);
this.picture = 'assets/img/test.jpg';
});
}