--- /dev/null
+package tool;
+
+import java.awt.Transparency;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.SampleModel;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+import javax.media.jai.JAI;
+import javax.media.jai.PlanarImage;
+
+
+/**
+ * This class displays basic information about the image.
+ */
+public class ImageTool {
+ /**
+ * The application entry point.
+ * @param args the command line arguments.
+ */
+ public static void main(String[] args) throws FileNotFoundException {
+ // We need one argument: the image filename.
+ if (args.length != 1) {
+ System.err.println("Usage: java tool.ImageTool image");
+ System.exit(0);
+ }
+ FileInputStream fi = new FileInputStream(args[0]);
+ // Open the image (using the name passed as a command line parameter)
+ PlanarImage pi = JAI.create("ImageRead", fi);
+
+ // Display image data. First, the image size (non-JAI related).
+ File image = new File(args[0]);
+ System.out.println("Image file size:" + image.length() + " bytes.");
+
+ // Now let's display the image dimensions and coordinates.
+ System.out.print("Dimensions: ");
+ System.out.print(pi.getWidth() + "x" + pi.getHeight() + " pixels");
+ System.out.println(" (from " + pi.getMinX() + "," + pi.getMinY() + " to " +
+ pi.getMaxX() + "," + pi.getMaxY() + ")");
+
+ // Tiles number, dimensions and coordinates.
+ System.out.print("Tiles:");
+ System.out.print(pi.getTileWidth() + "x" + pi.getTileHeight() + " pixels" +
+ " (" + pi.getNumXTiles() + "x" + pi.getNumYTiles() +
+ " tiles)");
+ System.out.print(" (from " + pi.getMinTileX() + "," + pi.getMinTileY() +
+ " to " + pi.getMaxTileX() + "," + pi.getMaxTileY() + ")");
+ System.out.println(" offset: " + pi.getTileGridXOffset() + "," +
+ pi.getTileGridXOffset());
+
+ // Display info about the SampleModel of the image.
+ SampleModel sm = pi.getSampleModel();
+ System.out.println("Number of bands: " + sm.getNumBands());
+ System.out.print("Data type: ");
+
+ switch (sm.getDataType()) {
+ case DataBuffer.TYPE_BYTE:
+ System.out.println("byte");
+
+ break;
+
+ case DataBuffer.TYPE_SHORT:
+ System.out.println("short");
+
+ break;
+
+ case DataBuffer.TYPE_USHORT:
+ System.out.println("unsigned short");
+
+ break;
+
+ case DataBuffer.TYPE_INT:
+ System.out.println("int");
+
+ break;
+
+ case DataBuffer.TYPE_FLOAT:
+ System.out.println("float");
+
+ break;
+
+ case DataBuffer.TYPE_DOUBLE:
+ System.out.println("double");
+
+ break;
+
+ case DataBuffer.TYPE_UNDEFINED:
+ System.out.println("undefined");
+
+ break;
+ }
+
+ // Display info about the ColorModel of the image.
+ ColorModel cm = pi.getColorModel();
+ System.out.println("Number of color components: " + cm.getNumComponents());
+ System.out.println("Bits per pixel: " + cm.getPixelSize());
+ System.out.print("Transparency: ");
+
+ switch (cm.getTransparency()) {
+ case Transparency.OPAQUE:
+ System.out.println("opaque");
+
+ break;
+
+ case Transparency.BITMASK:
+ System.out.println("bitmask");
+
+ break;
+
+ case Transparency.TRANSLUCENT:
+ System.out.println("translucent");
+
+ break;
+ }
+ }
+}