2 jjwwwww jjwwwww 于 2017.09.11 11:13 提问

Android关于相机快速拍照问题

我用的是Android cameraAPI2,现在遇到一点问题,我初步学会如何进行拍照,主要是通过IamgeReader来获得照片,但是我发现每次由拍照到成像的过程需要0.5秒左右,我希望每次拍照的时间在0.2秒以下,不知道有什么办法达到。
下面是我拍照的程序tackpicture()和imagereadlisten的部分代码,希望有相关开发经历的同志能给点意见。

 public void TakePicture(int rotation) {
        Log.e("MainTime",""+System.currentis());
        if (camera == null&&captureSession==null) {
            Toast.makeText(context,"设备还未准备就绪",Toast.LENGTH_SHORT)
                    .show();
            return;
        }
        try {
            if (captureRequestBuilder==null) {

                captureRequestBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
                captureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
                captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);

                Long max = characteristics.get(CameraCharacteristics.SENSOR_INFO_MAX_FRAME_DURATION);
                int a[] = characteristics.get(CameraCharacteristics.CONTROL_AVAILABLE_EFFECTS);
                for (int b : a) {
                    if (b == CameraCharacteristics.CONTROL_EFFECT_MODE_MONO) {
                        Log.e("Its", "YES");
                        //captureRequestBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CaptureRequest.CONTROL_EFFECT_MODE_MONO);
                        break;
                    }
                }
                Range<Integer> range1 = characteristics.get(CameraCharacteristics.SENSOR_INFO_SENSITIVITY_RANGE);

                captureRequestBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, range1.getUpper());
                captureRequestBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, 83333L);
                captureRequestBuilder.set(CaptureRequest.SENSOR_FRAME_DURATION, max / 6000);
            }
            // 根据设备方向计算设置照片的方向
            captureRequestBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
            //拍照
            captureRequestBuilder.addTarget(reader.getSurface());
            CaptureRequest mCaptureRequest = captureRequestBuilder.build();

            captureSession.capture(mCaptureRequest,null,handler);

        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
 @Override
        public void onImageAvailable(ImageReader reader) {
            Image image =reader.acquireNextImage();
            ByteBuffer buffer = image.getPlanes()[0].getBuffer();
            byte[] bytes= new byte[buffer.remaining()];
            buffer.get(bytes);//由缓冲区存入字节数组

            bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
            int width=bitmap.getWidth();
            int height=bitmap.getHeight();

            //bitmap.getPixels(pixel[T++],0,width,0,0,width,height);
            Log.e("MainTime",""+System.currentTimeMillis());
Csdn user default icon
上传中...
上传图片
插入图片