3 import java.awt.Transparency;
4 import java.awt.image.ColorModel;
5 import java.awt.image.DataBuffer;
6 import java.awt.image.SampleModel;
9 import java.io.FileInputStream;
10 import java.io.FileNotFoundException;
12 import javax.media.jai.JAI;
13 import javax.media.jai.PlanarImage;
17 * This class displays basic information about the image.
19 public class ImageTool {
21 * The application entry point.
22 * @param args the command line arguments.
24 public static void main(String[] args) throws FileNotFoundException {
25 // We need one argument: the image filename.
26 if (args.length != 1) {
27 System.err.println("Usage: java tool.ImageTool image");
30 FileInputStream fi = new FileInputStream(args[0]);
31 // Open the image (using the name passed as a command line parameter)
32 PlanarImage pi = JAI.create("ImageRead", fi);
34 // Display image data. First, the image size (non-JAI related).
35 File image = new File(args[0]);
36 System.out.println("Image file size:" + image.length() + " bytes.");
38 // Now let's display the image dimensions and coordinates.
39 System.out.print("Dimensions: ");
40 System.out.print(pi.getWidth() + "x" + pi.getHeight() + " pixels");
41 System.out.println(" (from " + pi.getMinX() + "," + pi.getMinY() + " to " +
42 pi.getMaxX() + "," + pi.getMaxY() + ")");
44 // Tiles number, dimensions and coordinates.
45 System.out.print("Tiles:");
46 System.out.print(pi.getTileWidth() + "x" + pi.getTileHeight() + " pixels" +
47 " (" + pi.getNumXTiles() + "x" + pi.getNumYTiles() +
49 System.out.print(" (from " + pi.getMinTileX() + "," + pi.getMinTileY() +
50 " to " + pi.getMaxTileX() + "," + pi.getMaxTileY() + ")");
51 System.out.println(" offset: " + pi.getTileGridXOffset() + "," +
52 pi.getTileGridXOffset());
54 // Display info about the SampleModel of the image.
55 SampleModel sm = pi.getSampleModel();
56 System.out.println("Number of bands: " + sm.getNumBands());
57 System.out.print("Data type: ");
59 switch (sm.getDataType()) {
60 case DataBuffer.TYPE_BYTE:
61 System.out.println("byte");
65 case DataBuffer.TYPE_SHORT:
66 System.out.println("short");
70 case DataBuffer.TYPE_USHORT:
71 System.out.println("unsigned short");
75 case DataBuffer.TYPE_INT:
76 System.out.println("int");
80 case DataBuffer.TYPE_FLOAT:
81 System.out.println("float");
85 case DataBuffer.TYPE_DOUBLE:
86 System.out.println("double");
90 case DataBuffer.TYPE_UNDEFINED:
91 System.out.println("undefined");
96 // Display info about the ColorModel of the image.
97 ColorModel cm = pi.getColorModel();
98 System.out.println("Number of color components: " + cm.getNumComponents());
99 System.out.println("Bits per pixel: " + cm.getPixelSize());
100 System.out.print("Transparency: ");
102 switch (cm.getTransparency()) {
103 case Transparency.OPAQUE:
104 System.out.println("opaque");
108 case Transparency.BITMASK:
109 System.out.println("bitmask");
113 case Transparency.TRANSLUCENT:
114 System.out.println("translucent");