How to identify contents of a byte[] is a JPEG?

前端 未结 6 1782
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 05:24

I have a small byte array (under 25K) that I receive and decode as part of a larger message envelope. Sometimes this is an image, furthermore it is a JPG. I have no context

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 05:45

    Quoting this wikipedia article:

    JPEG image files begin with FF D8 and end with FF D9. JPEG/JFIF files contain the ASCII code for "JFIF" (4A 46 49 46) as a null terminated string. JPEG/Exif files contain the ASCII code for "Exif" (45 78 69 66) also as a null terminated string, followed by more metadata about the file.

提交回复
热议问题