下面的将安卓camera的byte数组数据保存的图片文件没有宽高等参数是什么原因,byte[]数组为NV21格式
File file = null;
int width = camera.getParameters().getPreviewSize().width;//获取视频的宽度
int height = camera.getParameters().getPreviewSize().height;//获取照片的高度
YuvImage yuvImage = new YuvImage(data, camera.getParameters()
.getPictureFormat(), width, height, null);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
yuvImage.compressToJpeg(new Rect(0, 0, width, height), 80, byteArrayOutputStream);
byte[] jpegData = byteArrayOutputStream.toByteArray();
//创建图片文件
try {
String filePath = null;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
if (Build.VERSION.SDK_INT < 29) {
filePath = Environment.getExternalStorageDirectory().getCanonicalPath();
} else {
filePath = ct.getExternalFilesDir(null).getAbsolutePath();
}
}
file = new File(filePath, System.currentTimeMillis() + ".jpg");
FileOutputStream fos = new FileOutputStream(file);
fos.write(jpegData, 0, jpegData.length);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}