无法使用相机拍照

时间:2017-12-10 10:28:49

标签: android android-camera

我正在尝试开发一个可以在服务中拍照的Android应用程序。在实现服务之前,我试图在按钮单击上实现功能。我使用了以下位置的代码

how to capture an image in background without using the camera application

但是,我在执行Camera.takePicture()调用时遇到了异常情况。 LogCat显示以下

12-10 14:46:56.135 589-18809/? E/QCameraStateMachine: int32_t qcamera::QCameraStateMachine::procEvtPreviewReadyState(qcamera_sm_evt_enum_t, void *): Error!! cannot handle evt(24) in state(1)    
12-10 14:46:56.135 589-4574/? I/QCamera2HWI: [KPI Perf] static int qcamera::QCamera2HardwareInterface::pre_take_picture(struct camera_device *): X    
12-10 14:46:56.135 589-4574/? E/QCamera2HWI: static int qcamera::QCamera2HardwareInterface::take_picture(struct camera_device *): pre_take_picture failed with ret = -38    
12-10 14:46:56.135 589-4574/? I/QCameraHalWatchdog: Stopped Watchdog Thread (0ms)[take_picture]

我找不到任何关于“无法处理状态(1)中的evt(24)”的信息。无论是“qcamera :: QCamera2HardwareInterface :: pre_take_picture(struct camera_device *):X”

我没有在这里复制代码,因为代码已经是我之前提供的链接中的预先网络

我的min编译版本是KitKat,我使用的是Motorola Lenovo。

非常感谢您的帮助。

编辑**** 这是代码

Camera.PictureCallback mCall = new Camera.PictureCallback() {
    public void onPictureTaken(byte[] data, Camera camera) {
        Log.d(TAG, "------ In onPictureTaken");
        // decode the data obtained by the camera into a Bitmap
        // display.setImageBitmap(photo);
        Bitmap bitmapPicture = BitmapFactory.decodeByteArray(data, 0,
                data.length);
    }
};

...

Camera c = null;
try {
        c = Camera.open();

        SurfaceView sv = new SurfaceView(this);
        SurfaceHolder holder = sv.getHolder();
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

        c.setPreviewDisplay(holder);
        Camera.Parameters params = c.getParameters();
        params.setJpegQuality(100);
        c.setParameters(params);
        c.startPreview();

        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        c.setPreviewDisplay(holder);
        c.takePicture(null, null, mCall);
    } catch (Exception e) {
        Log.e(TAG, "---- problems with camera operation " + e.getMessage(), e);
        e.printStackTrace();
        Log.d(TAG, "------ 333333 ");
    } finally {
        if (c != null) {
            c.stopPreview();
            c.release();
        }
    }

0 个答案:

没有答案