我正在创建一个简单的YUV到JPEG图像转换器。为此,我需要从文件中获取YUV图像的大小。我很难在这里进行测试。但我需要从语法上获得这些细节。任何帮助将升值。如何从Android中的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();
}
}
}
我该如何解决这个问题?
我的天堂”尝试过,但似乎这个答案会帮助你,如果你对位图进行操作,而不是从文件中选择图像。 http://stackoverflow.com/questions/5960247/convert-bitmap-array-to-yuv-ycbcr-nv21 – VVB