发布网友 发布时间:2022-05-17 05:12
共2个回答
热心网友 时间:2023-10-09 02:25
byte[] bb=new byte[1024];
热心网友 时间:2023-10-09 02:26
亲测成功
public Bitmap decodeToBitMap(byte[] data, Camera _camera) {
if(data==null||_camera==null){
return null;
}
Camera.Size size = _camera.getParameters().getPreviewSize();
try {
YuvImage image = new YuvImage(data, ImageFormat.NV21, size.width,
size.height, null);
if (image != null) {
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();
return bmp;
}
} catch (Exception ex) {
}
return null;
}