Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework Ionic应用程序在打开本机摄像头后崩溃-错误20_Ionic Framework_Camera_Ionic4_Ionic Native_Ionic Plugins - Fatal编程技术网

Ionic framework Ionic应用程序在打开本机摄像头后崩溃-错误20

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.

我正在使用爱奥尼亚4上的cordova摄像头插件来拍摄一些图像

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) }
);