我正在創建一個簡單的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