aspose file tools
The moose likes Java in General and the fly likes Determine file (image) type from an InputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Determine file (image) type from an InputStream" Watch "Determine file (image) type from an InputStream" New topic
Author

Determine file (image) type from an InputStream

A Shehadi
Greenhorn

Joined: Jul 13, 2009
Posts: 19
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

Joined: Feb 08, 2005
Posts: 362
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

Joined: Jul 13, 2009
Posts: 19
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Determine file (image) type from an InputStream
 
Similar Threads
Writing input stream to file
JasperReports Problem with Image in Excel
SQL Server Exception
change tream input in process
Height and width of image from file upload