• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Determine file (image) type from an InputStream

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic