File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How to check if image is valid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to check if image is valid " Watch "How to check if image is valid " New topic
Author

How to check if image is valid

Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
I have a prolem. For my application I dynamically download images for results form a database. I use a4j:mediaOutput to display them. The problem is that some images returned are not valid to display (can't even display them on a PC). Is there a way I can detect such thing and display sth like 'image unavailable' in it's place? I don't mean what happens if my image isn't downloaded or I can't connect to get it - this is easily done by checking if the byte array is null. The problem is that if I download an image but i.e. it is corrupted so can't be displayed. Does anyone have any advice?
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hello,

ImageIO library has a lot of built in routines to get the format of the image. That format you can compare.
If you get something valid, proceed on else it is a corrupt image.

HTH,


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
Yes now I am using ImageReader.getFormatName() for this. I only wish the funcion would return the format in a mime type thing. So for example "image/jpeg" instead of "JPEG" - that way I could easily compare with what I download, without making some kind of a switch and predict the kind of images I might get.
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hello Adam,

If you are storing the MIME types in the server, as you already know the type is image.
So for custom basis may be, if you get something like this from the database for example
image/jpeg. You can take the substring after / and then compare the formats. I am not sure
how your MIME types are stored.
HTH,
Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
I though about that and I need to see the list of results I can get from getFormatName() and compere them with mime types. Maybe a simple upper case and 'equals' can do the trick. Thanks any way :>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to check if image is valid
 
Similar Threads
Handling session time out
retrieve multiple images from mysql
Buffering in Java
Need to show list of products with the image and specification on the jsp page
Display images on jsp from server using absolute path