addCallbackBuffer() registers the buffer to use OnPreviewFrame(). OnPreviewFrame() was registered setPreviewCallbackWithBuffer().
First, caculate the buffer size. frame_size is the buffer size.
example. width = 800 and height = 400, PreviewFormat is NV21 , frame_size is 576000 byte.
Camera.Parameters param = _camera.getParameters(); int imgformat = param.getPreviewFormat(); int bitsperpixel = ImageFormat.getBitsPerPixel(imgformat); int byteperpixel = bitsperpixel / 8; Camera.Size camerasize = param.getPreviewSize(); int frame_size = ((camerasize.width * camerasize.height) * bitsperpixel) / 8;
prepare callback function. If you process video image, you use data to received by callback.
private Camera.PreviewCallback mPreviewListener = new Camera.PreviewCallback() { @Override public void onPreviewFrame(byte[] data, Camera camera) { Log.d("camera", "onPreviewFrame size=" + data.length); //outputFile(data);//ファイル取得する関数 //_camera.addCallbackBuffer(data);//バッファを再利用する } };
register callback.
_camera.setPreviewCallbackWithBuffer(mPreviewListener);
register the buffer. If register the buffer, callback function is called soon.
byte[] frame = new byte[frame_size]; _camera.addCallbackBuffer(frame);
My source code is here.
ohuenno!
返信削除