ImageIO - get image type and exif data

后端 未结 3 1723
天涯浪人
天涯浪人 2020-12-05 09:55

Given some source file (or more generic - input stream), I need to find out

  • is it an image
  • if it is an image, then retrieve its type (png/jpeg/gif/etc
相关标签:
3条回答
  • 2020-12-05 10:24

    Last time I had to do this, a couple of years ago, the standard API couldn't read EXIF data. This library can do so though:

    http://www.drewnoakes.com/code/exif/

    0 讨论(0)
  • 2020-12-05 10:42

    Easy answer: Use https://github.com/drewnoakes/metadata-extractor/

    If you're crazy/brave/curious, you could get image type from the stream by reading the first few bytes (these are magic numbers). I believe the exif is generally at the start of the stream too.

    0 讨论(0)
  • 2020-12-05 10:46

    It's an old thread, but I was doing this recently and found the Apache Tika library useful. Particularly for analysing generic streams to detect what content is in them.

    Thought it might help others.

    http://tika.apache.org/

    0 讨论(0)
提交回复
热议问题