I am trying to get Exif data from YUV_420_888 image but it is not working. I tried several solutions like saving image to disk as jpeg, converting it to a input stream but nothing seems to work.
I capture YUV_420_888 image using android camera2 api. Then in the OnImageAvailableListener I get the image and try to read its EXIF data using ExifInterface APIs. But it is always empty. I tried all the approaches from this link to get the correct byte array.
Here is my code:
@Override
public void onImageAvailable(ImageReader imageReader) {
if (!isRecording) {
return;
}
Image image = imageReader.acquireNextImage();
File file = Util.getImagePath(context);
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(file);
outputStream.write(data);
//// This byte array I am making using all the approaches given in this link
https://stackoverflow.com/questions/44022062/converting-yuv-420-888-to-jpeg-and-saving-file-results-distorted-image
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath()); /// This is always empty
int currentIso = (int)exifInterface.getAttributeDouble(ExifInterface.TAG_ISO_SPEED_RATINGS, 0); /// Always 0
} catch (Exception e) {
e.printStackTrace();
}
image.close();
}
from camera2 How to get Exif data from YUV_420_888 image in image reader listener
No comments:
Post a Comment