Android录像截图把Yuv转为Jpg保存
原创
©著作权归作者所有:来自51CTO博客作者碼雲的原创作品,请联系作者获取转载授权,否则将追究法律责任
@Override
public void onPreviewFrame(byte[] data, Camera camera)
{
Size size = camera.getParameters().getPreviewSize();
try {
YuvImage image = new YuvImage(data, ImageFormat.NV21,size.width, size.height, null);
if (image != null) {
// 保存图片 ///
File file = new File(Environment.getExternalStorageDirectory().getPath() + File.separator+"picture.jpg");
FileOutputStream stream = new FileOutputStream(file);
if (image.compressToJpeg(new Rect(0, 0, size.width, size.height), 80, stream)) {
stream.flush();
stream.close();
}
//
/ 转为Bitmap /
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compressToJpeg(new Rect(0, 0, size.width, size.height), 80, stream);
Bitmap bmp=BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());
stream.close();
//
}
} catch (Exception ex) {
e.printStackTrace();
}
}