As the Android document said:
For formats besides YV12, the size of the buffer is determined by multiplying the preview image width, height, and bytes per pixel. The width and height can be read from getPreviewSize(). Bytes per pixel can be computed from getBitsPerPixel(int) / 8, using the image format from getPreviewFormat().
But most of online code using bitsperpixel to create buffer instead of the byteperpixel=bitsperpixel/8.
If I use following code with use the exact size in bytes of the image, will result in an error: E/Camera-JNI(3656): Callback buffer was too small! Expected 1336320 bytes, but got 890880 bytes! Why is that? Why the buffer need to be 8 time as big as the image size?
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);
1336320 is 1.5 X 890880, so I'd imagine bitsperpixel == 12, and in using int for bytesperpixel you are losing the remainder. e.g.
int bytesperpixel = 12 / 8
Will result in 1, not the 1.5 you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With