Answer the question
In order to leave comments, you need to log in
Get photo shooting time?
Hello everyone,
Please help, how to get the real date of shooting DateTime Original? exif.getAttribute(ExifInterface.TAG_DATETIME);
This returns the photo's last change. But not the shooting date.
Through EXIF-O-Matic, I see that there are tags. But the android does not see them. even the gallery doesn't see the DateTime Original.
Tell me what are the nuances of working with exif in android? How to read the real tag?
Answer the question
In order to leave comments, you need to log in
EXIF format
and this is how I pulled out the original date and, in addition, other tags, if count/count2(value size) is greater than 4, then value/value2 is the offset from the beginning of the TIFF header to the value, otherwise value/value2 is the value
private static void readExif(RandomAccessFile raf, int offset) throws IOException{
raf.seek(12+offset);
short entries = raf.readShort();
System.out.println(String.format("IFD entries = %d", entries));
for(short i=0; i<entries; i++){
short tag = raf.readShort();
short type = raf.readShort();
int count = raf.readInt();
int offsetOrValue = raf.readInt();
System.out.println(String.format("tag = %x type = %x count = %d offsetOrvalue = %d", tag, type, count, offsetOrValue));
long currPointer = raf.getFilePointer();
if(tag==-30871){
raf.seek(12+offsetOrValue);
short entries2 = raf.readShort();
for(short j=0; j<entries2; j++){
short tag2 = raf.readShort();
short type2 = raf.readShort();
int count2 = raf.readInt();
int offsetOrValue2 = raf.readInt();
System.out.println(String.format("tag = %x type = %d count = %d offsetOrvalue = %d", tag2, type2, count2, offsetOrValue2));
long currPointer2 = raf.getFilePointer();
if(tag2==-28669){
raf.seek(12+offsetOrValue2);
byte[] bb = new byte[count2];
raf.read(bb);
System.out.println("DateTimeOriginal = "+new String(bb));
raf.seek(currPointer2);
}
}
raf.seek(currPointer);
}
}
int nextOffset = raf.readInt();
if(nextOffset>0)
readExif(raf, nextOffset);
}
public static void main(String args[]) {
try {
RandomAccessFile raf = new RandomAccessFile(new File("D:\\Archive\\MyPhotosAndVideos\\IMG_20140920_130624.jpg"), "r");
raf.seek(12);
raf.readShort();
raf.readShort();
readExif(raf, raf.readInt());
raf.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Put a breakpoint inside onclick and see what it generally goes there on click, and then step by step see where and what does not work out.
I did not find this section of code on the site page at all. Is he there?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question