• Post Reply Bookmark Topic Watch Topic
  • New Topic

Determine file (image) type from an InputStream  RSS feed

 
A Shehadi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers....it's me again

Ok, my previous post was about extracting images from an Excel file and then writing them to disk, which I can now do with no problems...except when the image inserted in the Excel file is not supported by Java.

In this situation I can't use the ImageIO.write function because the image type is not known.

Does anyone know of a way to determine the image file type from an InputStream? The thing is, I need to use an InputStream to get the file type because the image itself is not in it's own file, so I can't just use the file extension.

Is this even possible?

Thanks!
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to look into the file headers

A quick reference can be found here

http://www.fastgraph.com/help/image_file_header_formats.html

 
A Shehadi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

But I solved it using Java Mime Magic Library although it's lacking documentation.

To use it you will need the jakarta-oro and commons-loging libraries (I used versions 2.0.8 and 1.1.1 respectively).

It did a pretty good job identifying images embedded in an Excel file (extracted using JExcelApi project library) and read with an InputStream.

Thanks a lot though. I had some issues with an image that JMimeMagic wouldn't detect and I think I'll have to take a look into the link you posted.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!