Android camera callbackbuffer buffer size must be 8 times larger than image?

As Android doc said:

For formats other than YV12, the buffer size is determined by multiplying the width, height, and preview byte per pixel. The width and height can be read from getPreviewSize (). Bytes per pixel can be calculated from using the image format from getPreviewFormat (). getBitsPerPixel(int) / 8

But most of the online code uses bitsperpixel

to create a buffer instead of byteperpixel=bitsperpixel/8

.

If I use the following code using the exact size in bytes of the image, it throws an error: E / Camera-JNI (3656): The callback buffer was too small! Expected 1336320 bytes, but received 890880 bytes! Why is this? Why does the buffer have to be 8 times the size of the image?

Camera.Parameters parameters=mCamera.getParameters();
parameters.setPreviewSize(width,height);
mCamera.setParameters(parameters);

int previewFormat=parameters.getPreviewFormat();
int bitsperpixel=ImageFormat.getBitsPerPixel(previewFormat);
int byteperpixel=bitsperpixel/8;
Camera.Size camerasize=parameters.getPreviewSize();
int frame_bytesize=((camerasize.width*camerasize.height)*byteperpixel);

//create buffer
byte[]frameBuffer=new byte[frame_bytesize];

//buffer registry 
mCamera.addCallbackBuffer(frameBuffer);

      

+3


source to share


1 answer


1336320 is 1.5 X 890880, so I would assume that bitperpixel == 12 and when using int for bytesperpixel you lose the remainder. eg.

int bytesperpixel = 12 / 8

      



The result will be 1, not 1.5.

+8


source







All Articles