问题
Why is the data byte array size different for onPictureTaken(byte[] data, Camera camera) and onPreviewFrame(byte[] data, Camera camera). The former has the original image and hence gives me a clean image and the latter gives me a pixelated image. I am not using onPictureTaken because it does not get triggered sometimes. If my picture size is 1600 x 1400 and screen size is 800 x 480 onPictureTaken gives me 1600 x 1400 and onPreviewFrame gives me 800 x 480
This is my code:
mCamera.setOneShotPreviewCallback(new Camera.PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
int format = parameters.getPreviewFormat();
//YUV formats require more conversion
if (format == ImageFormat.NV21 || format == ImageFormat.YUY2 || format == ImageFormat.NV16) {
int w = parameters.getPreviewSize().width;
int h = parameters.getPreviewSize().height;
// Get the YuV image
YuvImage yuv_image = new YuvImage(data, format, w, h, null);
}
I have been stuck with this issue for one week.
P.S. - In case of negative ratings please state the reason
回答1:
Why is the data byte array size different for onPictureTaken(byte[] data, Camera camera) and onPreviewFrame(byte[] data, Camera camera).
Because they are different images with different resolutions in different encodings. It would be a minor miracle if they were the same size.
The former has the original image and hence gives me a clean image and the latter gives me a pixelated image
Preview frames are generally of lower quality, because they need to be captured at a high rate of speed.
I am not using onPictureTaken because it does not get triggered sometimes
While I have encountered many problems with the camera APIs, that is not one of them.
onPreviewFrame gives me 800 x 480
You specify the preview resolution in setPreviewSize() on Camera.Parameters.
来源:https://stackoverflow.com/questions/32727335/data-byte-array-size-different-for-onpicturetaken-and-onpreviewframe