public void onPreviewFrame(final byte[] mData, Camera camera) {
BitMap mBmp = BitmapFactory.decodeByteArray(mData, 0, mData.length);
以上代码将返回null ,原因在于mData的格式一般为为yuv格式,非Jpeg,需作转换:
YuvImage yuvimage=new YuvImage(mData, ImageFormat.NV21, mSize.width, mSize.height, null);
bos = new ByteArrayOutputStream();
yuvimage.compressToJpeg(new Rect(0, 0, mSize.width, mSize.height), mQulity, bos);
byte[] jdata = bos.toByteArray();
mBmp = BitmapFactory.decodeByteArray(jdata, 0, jdata.length);
网友评论