Android EXIF data always 0, how to change it?

后端 未结 5 2174
[愿得一人]
[愿得一人] 2021-02-12 03:38

I have an app that captures photos using the native Camera and then uploads them to a server. My problem is that all the photos have an EXIF orientation value of 0,

5条回答
  •  离开以前
    2021-02-12 04:02

    You have accepted your own answer as solution. My rant is just useful side-info, anyways...

    The "However..." in your Answer suggests while you now know the cause, you don't have a fix.

    Turns out my code was able to set the EXIF data, but there is a discrepancy between how Android interprets this data and how iOS... interprets it.

    This could be an endianness issue. You can try manually changing the endianness setting of Exif by opening your jpeg in a hex editor and finding...

    • The bytes 45 78 69 66 (makes "Exif" text) followed by two zero bytes 00 00.
    • Then it should be 49 49 (makes "II" text) which means read data as little endian format.
    • If you replace it with 4D 4D (or "MM" text) then the reading side will consider data as big endian.

    Test this in iOS to see if numbers are now correct.

    and regarding this...

    However, setting 3 shows up as0 on iOS and the image is sideways in Chrome.
    Setting 6 shows up as 3 on iOS and the image looks right in Chrome.

    Only thing I can add is that iOS Mac is Big Endian* and Android/PC is Little Endian. Essentially Little Endian reads/writes bytes as right-to-left whilst Big Endian is opposite.

    In binary : 011 means 3 and 110 means 6. The difference between 3 and 6 is simply the reading order of those bits of ones & zeroes. So a system that reads as zero-one-one gets a result of 3 but the other Endian system will read a byte with same bits as one-one-zero and tell you result is a 6. I can't explain why "3 shows up as 0" without a test file to analyse bytes but it's a strange result to me.


    *note: While Macs are Big Endian, double-checking says iOS uses Little Endian system after all. Your numbers still suggest a Big vs Little Endian issue though.

提交回复
热议问题