Java Doc for ImageInfo.java in  » J2EE » Pustefix » de » schlund » pfixxml » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Pustefix » de.schlund.pfixxml 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   de.schlund.pfixxml.ImageInfo

ImageInfo
public class ImageInfo (Code)
Get file format, image resolution, number of bits per pixel and optionally number of images from JPEG, GIF, BMP, PCX, PNG, IFF, RAS, PBM, PGM, PPM and PSD files (or input streams).

Use the class like this:

 ImageInfo ii = new ImageInfo();
 ii.setInput(in); // in can be InputStream or RandomAccessFile
 ii.setDetermineImageNumber(true); // default is false
 if (!ii.check()) {
 System.err.println("Not a supported image file format.");
 } else {
 System.out.println(ii.getFormatName() + ", " + ii.getMimeType() + 
 ", " + ii.getWidth() + " x " + ii.getHeight() + " pixels, " + 
 ii.getBitsPerPixel() + " bits per pixel, " + ii.getNumberOfImages() +
 " image(s).");
 }
 
You can also use this class as a command line program. Call it with a number of image file names as parameters:
 java ImageInfo *.jpg *.png *.gif
 
or call it without parameters and pipe data to it:
 cat image.jpg | java ImageInfo
 

Known limitations:

  • When the determination of the number of images is turned off, GIF bits per pixel are only read from the global header. For some GIFs, local palettes change this to a typically larger value. To be certain to get the correct color depth, call setDetermineImageNumber(true) before calling check(). The complete scan over the GIF file will take additional time.
  • Transparency information is not included in the bits per pixel count. Actually, it was my decision not to include those bits, so it's a feature! ;-)

Requirements:

  • Java 1.1 or higher

The latest version can be found at http://www.geocities.com/marcoschmidt.geo/image-info.html.

Written by Marco Schmidt.

This class is contributed to the Public Domain. Use it at your own risk.

Last modification 2002-04-10.

History:

  • 2001-08-24 Initial version.
  • 2001-10-13 Added support for the file formats BMP and PCX.
  • 2001-10-16 Fixed bug in read(int[], int, int) that returned
  • 2002-01-22 Added support for file formats Amiga IFF and Sun Raster (RAS).
  • 2002-01-24 Added support for file formats Portable Bitmap / Graymap / Pixmap (PBM, PGM, PPM) and Adobe Photoshop (PSD). Added new method getMimeType() to return the MIME type associated with a particular file format.
  • 2002-03-15 Added support to recognize number of images in file. Only works with GIF. Use ImageInfo.setDetermineImageNumber with true as argument to identify animated GIFs ( ImageInfo.getNumberOfImages() will return a value larger than 1).
  • 2002-04-10 Fixed a bug in the feature 'determine number of images in animated GIF' introduced with version 1.1. Thanks to Marcelo P. Lima for sending in the bug report.


Field Summary
final public static  intFORMAT_BMP
     Return value of ImageInfo.getFormat() for BMP streams.
final public static  intFORMAT_GIF
     Return value of ImageInfo.getFormat() for GIF streams.
final public static  intFORMAT_IFF
     Return value of ImageInfo.getFormat() for IFF streams.
final public static  intFORMAT_JPEG
     Return value of ImageInfo.getFormat() for JPEG streams.
final public static  intFORMAT_PBM
     Return value of ImageInfo.getFormat() for PBM streams.
final public static  intFORMAT_PCX
     Return value of ImageInfo.getFormat() for PCX streams.
final public static  intFORMAT_PGM
     Return value of ImageInfo.getFormat() for PBM streams.
final public static  intFORMAT_PNG
     Return value of ImageInfo.getFormat() for PNG streams.
final public static  intFORMAT_PPM
     Return value of ImageInfo.getFormat() for PBM streams.
final public static  intFORMAT_PSD
     Return value of ImageInfo.getFormat() for PBM streams.
final public static  intFORMAT_RAS
     Return value of ImageInfo.getFormat() for RAS streams.


Method Summary
public  booleancheck()
     Call this method after you have provided an input stream or file using ImageInfo.setInput(InputStream) or ImageInfo.setInput(DataInput) .
public  intgetBitsPerPixel()
     If ImageInfo.check() was successful, returns the image's number of bits per pixel.
public  intgetFormat()
     If ImageInfo.check() was successful, returns the image format as one of the FORMAT_xyz constants from this class.
public  StringgetFormatName()
     If ImageInfo.check() was successful, returns the image format's name.
public  intgetHeight()
     If ImageInfo.check() was successful, returns one the image's vertical resolution in pixels.
public  StringgetMimeType()
     If ImageInfo.check() was successful, returns a String with the MIME type of the format. MIME type, e.g.
public  intgetNumberOfImages()
     Returns the number of images in the examined file if setDetermineImageNumber(true); was called before a successful call to ImageInfo.check() .
public  intgetWidth()
     If ImageInfo.check() was successful, returns one the image's horizontal resolution in pixels.
public static  voidmain(String[] args)
     To use this class as a command line application, give it either some file names as parameters (information on them will be printed to standard output, one line per file) or call it with no parameters.
public  voidsetCollectComments(boolean newValue)
    
public  voidsetDetermineImageNumber(boolean newValue)
     Specify whether the number of images in a file are to be determined - default is false.
public  voidsetInput(DataInput dataInput)
     Set the input stream to the argument stream (or file).
public  voidsetInput(InputStream inputStream)
     Set the input stream to the argument stream (or file).

Field Detail
FORMAT_BMP
final public static int FORMAT_BMP(Code)
Return value of ImageInfo.getFormat() for BMP streams.



FORMAT_GIF
final public static int FORMAT_GIF(Code)
Return value of ImageInfo.getFormat() for GIF streams.



FORMAT_IFF
final public static int FORMAT_IFF(Code)
Return value of ImageInfo.getFormat() for IFF streams.



FORMAT_JPEG
final public static int FORMAT_JPEG(Code)
Return value of ImageInfo.getFormat() for JPEG streams.



FORMAT_PBM
final public static int FORMAT_PBM(Code)
Return value of ImageInfo.getFormat() for PBM streams.



FORMAT_PCX
final public static int FORMAT_PCX(Code)
Return value of ImageInfo.getFormat() for PCX streams.



FORMAT_PGM
final public static int FORMAT_PGM(Code)
Return value of ImageInfo.getFormat() for PBM streams.



FORMAT_PNG
final public static int FORMAT_PNG(Code)
Return value of ImageInfo.getFormat() for PNG streams.



FORMAT_PPM
final public static int FORMAT_PPM(Code)
Return value of ImageInfo.getFormat() for PBM streams.



FORMAT_PSD
final public static int FORMAT_PSD(Code)
Return value of ImageInfo.getFormat() for PBM streams.



FORMAT_RAS
final public static int FORMAT_RAS(Code)
Return value of ImageInfo.getFormat() for RAS streams.





Method Detail
check
public boolean check()(Code)
Call this method after you have provided an input stream or file using ImageInfo.setInput(InputStream) or ImageInfo.setInput(DataInput) . If true is returned, the file format was known and you information about its content can be retrieved using the various getXyz methods. if information could be retrieved from input



getBitsPerPixel
public int getBitsPerPixel()(Code)
If ImageInfo.check() was successful, returns the image's number of bits per pixel. Does not include transparency information like the alpha channel. number of bits per image pixel



getFormat
public int getFormat()(Code)
If ImageInfo.check() was successful, returns the image format as one of the FORMAT_xyz constants from this class. Use ImageInfo.getFormatName() to get a textual description of the file format. file format as a FORMAT_xyz constant



getFormatName
public String getFormatName()(Code)
If ImageInfo.check() was successful, returns the image format's name. Use ImageInfo.getFormat() to get a unique number. file format name



getHeight
public int getHeight()(Code)
If ImageInfo.check() was successful, returns one the image's vertical resolution in pixels. image height in pixels



getMimeType
public String getMimeType()(Code)
If ImageInfo.check() was successful, returns a String with the MIME type of the format. MIME type, e.g. image/jpeg



getNumberOfImages
public int getNumberOfImages()(Code)
Returns the number of images in the examined file if setDetermineImageNumber(true); was called before a successful call to ImageInfo.check() . number of images in file



getWidth
public int getWidth()(Code)
If ImageInfo.check() was successful, returns one the image's horizontal resolution in pixels. image width in pixels



main
public static void main(String[] args)(Code)
To use this class as a command line application, give it either some file names as parameters (information on them will be printed to standard output, one line per file) or call it with no parameters. It will then check data given to it via standard input.
Parameters:
  args - the program arguments which must be file names



setCollectComments
public void setCollectComments(boolean newValue)(Code)



setDetermineImageNumber
public void setDetermineImageNumber(boolean newValue)(Code)
Specify whether the number of images in a file are to be determined - default is false. Will only make a difference with file formats that do support more than one image like GIF. If this method is called with true as argument, the actual number of images can be queried via ImageInfo.getNumberOfImages() after a successful call to ImageInfo.check() .
Parameters:
  newValue - will the number of images be determined?



setInput
public void setInput(DataInput dataInput)(Code)
Set the input stream to the argument stream (or file). Note that java.io.RandomAccessFile implements java.io.DataInput .
Parameters:
  dataInput - the input stream to read from



setInput
public void setInput(InputStream inputStream)(Code)
Set the input stream to the argument stream (or file).
Parameters:
  inputStream - the input stream to read from



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.