生成Image对象

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/ChaoLi_Chen/article/details/100016310

 Image对象在 拍照的时候在底层可以获取到,主要是拍照的时候用的ZSL拍照需要两次处理,当第一次拍照获取到Image之后然后设置用ImageWrite 的queueInputImage 方法进行降噪处理和曝光值处理,目前公司的需求是需要 第一次拍照的时候 就将一个Image传递下去,Image不能直接获取,最后想到了一个方法,读取一个byte 然后再填充到 Image里面

具体关键代码如下,仅做笔记。


            if(mImageWriter == null) {
                mImageWriter = ImageWriter.newInstance(mCaptureSession[getMainCameraId()].getInputSurface(), 11);

            }


            //从ImageWriter 获取一张Image图片 
            Image image = mImageWriter.dequeueInputImage();

            //获取Image的buffer
            ByteBuffer frame = image.getPlanes()[0].getBuffer();


            String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/IMG_19700818_124311.raw";
            Log.d(TAG," wuyhdbg  absolutePath " +  absolutePath);

            Path path = Paths.get(absolutePath);

            FileChannel fileChannel = null;
            try {
                fileChannel = FileChannel.open(path, EnumSet.of(StandardOpenOption.READ,StandardOpenOption.WRITE));
            //将读取的buffer写入到 Buffer中
                fileChannel.read(frame);
            } catch (IOException e) {
                e.printStackTrace();
            }

            //直接传递到底层
            mImageWriter.queueInputImage(image);
            Log.d(TAG,"chencl_   mImageWriter mImageWriter  after ........ ");



            mCaptureSession[id].capture(captureBuilder.build(), new CameraCaptureSession.CaptureCallback() {

                @Override
                public void onCaptureCompleted(CameraCaptureSession session,
                                               CaptureRequest request,
                                               TotalCaptureResult result) {
                    Log.d(TAG, "captureStillPictureForCommon onCaptureCompleted: " + id);
										mLastTotalCaptureResult = result;
                }

                @Override
                public void onCaptureFailed(CameraCaptureSession session,
                                            CaptureRequest request,
                                            CaptureFailure result) {
                    Log.d(TAG, "captureStillPictureForCommon onCaptureFailed: " + id);
                }

                @Override
                public void onCaptureSequenceCompleted(CameraCaptureSession session, int
                        sequenceId, long frameNumber) {
                    Log.d(TAG, "captureStillPictureForCommon onCaptureSequenceCompleted: " + id);
                    if (mUI.getCurrentProMode() != ProMode.MANUAL_MODE) {
                        unlockFocus(id);
                    } else {
                        enableShutterAndVideoOnUiThread(id);
                    }
                }
            }, mCaptureCallbackHandler);
        }
    }

猜你喜欢

转载自blog.csdn.net/ChaoLi_Chen/article/details/100016310
今日推荐