我正在使用离子照相机预览插件,因为我只想捕获图像的一小部分,而不是整个屏幕可见的图像。
下面是代码
constructor(private camera: Camera,
private cameraPreview: CameraPreview){
this.cameraPreviewOn = false
this.cameraPreviewOrientation = GlobalVariables.LANDSCAPE
this.cameraPreviewOpts.width = window.screen.width
this.cameraPreviewOpts.height = (window.screen.width*2/3)
}
/**
* uses camera preview to take a picture
*/
captureUsingCameraPreviewNew(){
// take a picture
this.cameraPreview.takeSnapshot(this.pictureOpts).then(async (imageData) => {
this.cameraPreviewOn = false
this.cameraPreview.stopCamera();
this.presentToast("Image captured successfully")
// imageData is a base64 encoded string
var base64Image = "data:image/jpeg;base64," + imageData;
}, (err) => {
console.log(err);
this.cameraPreviewOn = false
alert('failed to take picture')
});
}
我希望图像只是预览中的黑色区域,但是它将占据整个屏幕,如下所示 https://firebasestorage.googleapis.com/v0/b/mitbusinesscardscanner.appspot.com/o/1564565101379?alt=media&token=df4aff15-bef7-46d2-9a15-b137bda0adac
它不尊重高度值