1、onPreviewFrame运行一段时间后便不进入回调函数
tip:1.在onPreviewFrame函数里加入mCamera.addCallbackBuffer(data);
2.surfaceChanged里加入mCamera.addCallbackBuffer(gBuffer);
mCamera.setPreviewCallbackWithBuffer(this);
3.surfaceCreated里mCamera.setPreviewDisplay(mSurfaceHolder);
gBuffer = previewBuffer();
mCamera.addCallbackBuffer(gBuffer);
mCamera.setPreviewCallbackWithBuffer(this);
4.private byte[] previewBuffer() {
Log.d("Function", "previewBuffer iniciado");
int bufferSize;
byte buffer[];
int bitsPerPixel;
Camera.Parameters mParams = mCamera.getParameters();
Camera.Size mSize = mParams.getPreviewSize();
Log.d("Function", "previewBuffer: preview size=" + mSize.height + " " + mSize.width);
int mImageFormat = mParams.getPreviewFormat();
if (mImageFormat == ImageFormat.YV12) {
int yStride = (int) Math.ceil(mSize.width / 16.0) * 16;
int uvStride = (int) Math.ceil((yStride / 2) / 16.0) * 16;
int ySize = yStride * mSize.height;
int uvSize = uvStride * mSize.height / 2;
bufferSize = ySize + uvSize * 2;
buffer = new byte[bufferSize];
Log.d("Function", "previewBuffer: buffer size=" + Integer.toString(bufferSize));
return buffer;
}
bitsPerPixel = ImageFormat.getBitsPerPixel(mImageFormat);
bufferSize = (int) (mSize.height * mSize.width * ((bitsPerPixel / (float) 8)));
buffer = new byte[bufferSize];
Log.d("Function", "previewBuffer: buffer size=" + Integer.toString(bufferSize));
return buffer;
}
5.在每次改变相机参数时,在startView之前加上 mCamera.addCallbackBuffer(gBuffer);
mCamera.setPreviewCallbackWithBuffer(this);
总结:以上tips都是从网上各处搜罗,自己各种实验总结而来。乐意分享~