1.startPreview之前设置PreviewCallback
mCameraDevice.setPreviewCallback(mPreviewCallback);
mCameraDevice.startPreview(); 2. 获取preview数据
private final class PreviewCallback implements
android.hardware.Camera.PreviewCallback {
public void onPreviewFrame(byte[] data, android.hardware.Camera camera) {
Size size = mParameters.getPreviewSize();
YuvImage yuvimage = new YuvImage(data, ImageFormat.NV21, size.width,
size.height, null);
ByteArrayOutputStream outputSteam = new ByteArrayOutputStream();
yuvimage.compressToJpeg(new Rect(0, 0, size.width, size.height), 80, outputSteam);
}
}