[英]Android camera preview callback buffer not filled: is always full of zeros
While Camera.PreviewCallback#onPreviewFrame
does get called, the passed byte[]
buffer is not populated by the camera: it is always full of zeros. 当
Camera.PreviewCallback#onPreviewFrame
确实被调用时,相机不会填充传递的byte[]
缓冲区:它始终充满零。
The reason why I'm using the deprecated API is that I was getting a very low framerate using the newer one. 我使用不推荐使用的API的原因是,使用较新的API时帧率非常低。 Since my cameras are considered
LEGACY
, I was recommended to try the deprecated API. 由于我的相机被认为是
LEGACY
,因此建议尝试不推荐使用的API。
My code, where the callback does get called, but the buffer is empty: 我的代码,确实调用了回调,但是缓冲区为空:
camera = Camera.open();
camera.setParameters(configurator.getParameters());
Size size = configurator.getOutputSize();
camera.addCallbackBuffer(new byte[size.getWidth() * size.getHeight() * ImageFormat.getBitsPerPixel(ImageFormat.YV12) / 8]);
camera.setPreviewCallbackWithBuffer(this);
camera.startPreview();
One weird thing I see in the log is the following: when I call camera.setPreviewCallbackWithBuffer(this);
我在日志中看到的一件奇怪的事情是:当我调用
camera.setPreviewCallbackWithBuffer(this);
, this debug message appears: D/Camera-JNI: (tid:3466)[release camera] - X context=0x0
. ,将显示以下调试消息:
D/Camera-JNI: (tid:3466)[release camera] - X context=0x0
。
Also, all modifications to the buffer are cleared: the buffer is actually being filled with zeros before each call to the callback. 同样,所有对缓冲区的修改都将被清除:在每次调用回调之前,缓冲区实际上都是用零填充的。
The issue was the lack of light compared to the exposure time: I have set my preview FPS range to the maximum one, but this caused the exposure time to be too low compared to the lighting in my room. 问题是与曝光时间相比光线不足:我将预览FPS范围设置为最大,但与房间的照明相比,这导致曝光时间太短。 The result was a pitch black image, except when I pointed the camera directly at a light source.
结果是黑色的图像,除非我直接将相机对准光源。 Changing the FPS range to a lower one fixed my issue.
将FPS范围更改为较低的值可以解决我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.