I am creating a simple YUV to JPEG image converter.for that I need to get the size of YUV image from the file. I hard corded here for testing. but I need to get those details grammatically. Any help will appreciate.
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();
}
}
}
But output was horrible. Please see attached image.
How can I solve this issue ?