转自文章《Android--将NV21图像保存成JPEG》http://blog.csdn.net/tanmengwen/article/details/41412425
将NV21数据压缩成JPEG,并得到JPEG byte数据,解压JPEG byte数据成一张Bitmap
[java] view plain copy
- @Override
- public void onPreviewFrame(byte[] bytes, Camera camera) {
- YuvImage image = new YuvImage(bytes, ImageFormat.NV21, width, height, null); //ImageFormat.NV21 640 480
- ByteArrayOutputStream outputSteam = new ByteArrayOutputStream();
- image.compressToJpeg(new Rect(0, 0, image.getWidth(), image.getHeight()), 70, outputSteam); // 将NV21格式图片,以质量70压缩成Jpeg,并得到JPEG数据流
- byte[] jpegData = outputSteam.toByteArray(); //从outputSteam得到byte数据
- Options options = new BitmapFactory.Options();
- options.inSampleSize = 1;
- Bitmap bmp = BitmapFactory.decodeStream(jpegData, null, options);
- }