Ionic framework Ionic应用程序在打开本机摄像头后崩溃-错误20
我正在使用爱奥尼亚4上的cordova摄像头插件来拍摄一些图像Ionic framework Ionic应用程序在打开本机摄像头后崩溃-错误20,ionic-framework,camera,ionic4,ionic-native,ionic-plugins,Ionic Framework,Camera,Ionic4,Ionic Native,Ionic Plugins,我正在使用爱奥尼亚4上的cordova摄像头插件来拍摄一些图像 takePicture() { console.log(' camera takePicture '); const options: CameraOptions = { quality: 100, destinationType: this.camera.DestinationType.DATA_URL, encodingType: this.camera.EncodingType.
takePicture() {
console.log(' camera takePicture ');
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
this.selectedImage = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
// Handle error
console.log('Camera issue:' + err);
});
}
应用程序不会崩溃,但此代码始终返回摄像头问题:20,并且摄像头界面从未出现在手机屏幕上
我试图像这样修改config.xml文件,因为我认为android权限有问题,但仍然不起作用:
<config-file mode="merge" parent="/*" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<!-- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
</config-file>
我不知道怎么解决这个问题,我需要一些帮助。
谢谢 您应该使用
cordova插件相机预览
插件在爱奥尼亚操作相机。请注意,此插件仅与Android和iOS兼容
安装时请使用:
ionic cordova plugin add cordova-plugin-camera-preview
npm install @ionic-native/camera-preview
用法:// camera options (Size and location). In this example, the preview uses the rear camera and displays the preview in the back of the webview
const cameraPreviewOpts: CameraPreviewOptions = {
x: 0,
y: 0,
width: window.screen.width,
height: window.screen.height,
camera: 'rear',
tapPhoto: true,
previewDrag: true,
toBack: true,
alpha: 1
}
// start camera
this.cameraPreview.startCamera(cameraPreviewOpts).then(
(res) => { console.log(res) },
(err) => { console.log(err) }
);
// camera options (Size and location). In this example, the preview uses the rear camera and displays the preview in the back of the webview
const cameraPreviewOpts: CameraPreviewOptions = {
x: 0,
y: 0,
width: window.screen.width,
height: window.screen.height,
camera: 'rear',
tapPhoto: true,
previewDrag: true,
toBack: true,
alpha: 1
}
// start camera
this.cameraPreview.startCamera(cameraPreviewOpts).then(
(res) => { console.log(res) },
(err) => { console.log(err) }
);