我正在创建一个简单的 YUV 到 JPEG 图像转换器。为此我需要从文件中获取 YUV 图像的大小。我在这里硬线测试。但我需要从语法上获取这些细节。任何帮助将不胜感激。
private void covertToYuvImage() {
ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
String yuvImagePath = selectedFolder+yuvImageList.get(0); //Path to YUV image
File file = new File(yuvImagePath);
byte[] bFile = new byte[(int) file.length()];
try{
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
}
catch (Exception e){
e.printStackTrace();
}
YuvImage yuvImage = new YuvImage(bFile, ImageFormat.NV21,2048,1536,null);
yuvImage.compressToJpeg( new Rect(0, 0, 2048, 1536), 100, baoStream);
File imgFile = new File(selectedFolder, "NewImage.jpeg");
if (!imgFile.exists()) {
FileOutputStream img;
try {
img = new FileOutputStream(imgFile);
img.write(baoStream.toByteArray());
img.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我该如何解决这个问题?