将YUV420sp转Bitmtp
public class YUV420spToBitmapUtils {
/**
* @param data yuv420sp数据;
* @param width 视频的宽度;
* @param height 视频的高度;
* @return
*/
public static Bitmap yuv420spToBitmap(byte[] data, int width, int height) {
Bitmap bitmap = null;
YuvImage image = new YuvImage(data, ImageFormat.NV21, width, height, null);
if (image != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compressToJpeg(new Rect(0, 0, width, height), 100, stream);
bitmap = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return bitmap;
}
}