JavaXT

Image Class

Used to open, resize, rotate, crop and save images.

Constructors

public Image( String PathToImageFile )
public Image( java.io.File file )
public Image( java.io.InputStream InputStream )
public Image( byte[] byteArray )
public Image( int width, int height )
public Image( java.awt.image.BufferedImage bufferedImage )
public Image( java.awt.image.RenderedImage img )
public Image( String text, String fontName, int fontSize, int r, int g, int b )
public Image( String text, java.awt.Font font, int r, int g, int b )

Methods

addImage( java.awt.image.BufferedImage in, int x, int y, boolean expand ) returns void
Used to add an image "overlay" to the existing image at a given position. This method can also be used to create image mosiacs.
addImage( javaxt.io.Image in, int x, int y, boolean expand ) returns void
Used to add an image "overlay" to the existing image at a given position. This method can also be used to create image mosiacs.
addPoint( int x, int y, int r, int g, int b ) returns void
Simple drawing function used to set color of a specific pixel in the image.
addText( String text, int x, int y ) returns void
Used to add text to the image at a given position.
text
xLower left coordinate of the text
yLower left coordinate of the text
addText( String text, int x, int y, java.awt.Font font, int r, int g, int b ) returns void
Used to add text to the image at a given position.
text
xLower left coordinate of the text
yLower left coordinate of the text
fontFont
rValue for the red channel (0-255)
gValue for the green channel (0-255)
bValue for the blue channel (0-255)
addText( String text, int x, int y, String fontName, int fontSize, int r, int g, int b ) returns void
Used to add text to the image at a given position.
text
xLower left coordinate of the text
yLower left coordinate of the text
fontNameName of the font face (e.g. "Tahoma", "Helvetica", etc.)
fontSizeSize of the font
rValue for the red channel (0-255)
gValue for the green channel (0-255)
bValue for the blue channel (0-255)
copy( ) returns javaxt.io.Image
Returns a copy of the current image.
copyRect( int x, int y, int width, int height ) returns javaxt.io.Image
Returns a copy of the image at a given rectangle.
crop( int x, int y, int width, int height ) returns void
Used to subset or crop an image.
desaturate( ) returns void
Used to completely desaturate an image (creates a gray-scale image).
desaturate( double percent ) returns void
Used to desaturate an image by a specified percentage (expressed as a double or float). The larger the percentage, the greater the desaturation and the "grayer" the image. Valid ranges are from 0-1.
equals( Object obj ) returns boolean
Used to compare this image to another. If the ARGB values match, this method will return true.
flip( ) returns void
Used to flip an image along it's y-axis (horizontal). Vertical flipping is supported via the rotate method (i.e. rotate +/-180).
getAttributeValue( org.w3c.dom.NamedNodeMap attrCollection, String attrName ) returns String
Used to return the value of a given node attribute. The search is case insensitive. If no match is found, returns an empty string.
getBufferedImage( ) returns java.awt.image.BufferedImage
Returns the java.awt.image.BufferedImage represented by the current image.
getBufferedImage( int width, int height, boolean maintainRatio ) returns java.awt.image.BufferedImage
Used to retrieve a scaled copy of the current image.
getByteArray( ) returns byte[]
Returns the image as a jpeg byte array. Output quality is set using the setOutputQuality method.
getByteArray( String format ) returns byte[]
Returns the image as a byte array.
getColor( int x, int y ) returns java.awt.Color
Used to retrieve the color (ARGB) values for a specific pixel in the image. Returns a java.awt.Color object. Note that input x,y values are relative to the upper left corner of the image, starting at 0,0.
getCorners( ) returns float[]
Used to retrieve the corner coordinates of the image. Coordinates are supplied in clockwise order starting from the upper left corner. This information is particularly useful for generating drop shadows, inner and outer glow, and reflections. NOTE: Coordinates are not updated after resize(), rotate(), or addImage()
getExifData( ) returns byte[]
Returns the raw EXIF byte array (marker 0xE1).
getExifTags( ) returns java.util.HashMap
Used to parse EXIF metadata and return a list of key/value pairs found in the metadata. Values can be Strings, Integers, or raw Byte Arrays. You can retrieve specific EXIF metadata values like this:
    javaxt.io.Image image = new javaxt.io.Image("/temp/image.jpg");
    java.util.HashMap<Integer, Object> exif = image.getExifTags();
    System.out.println("Date: " + exif.get(0x0132));
    System.out.println("Camera: " + exif.get(0x0110));
    System.out.println("Focal Length: " + exif.get(0x920A));
    System.out.println("F-Stop: " + exif.get(0x829D));
    System.out.println("Shutter Speed: " + exif.get(0x829A));
   
Note that the EXIF MakerNote is not parsed.
getGPSCoordinate( ) returns double[]
Returns the x/y (lon/lat) coordinate tuple for the image. Value is derived from EXIF GPS metadata (tags 0x0001, 0x0002, 0x0003, 0x0004).
getGPSDatum( ) returns String
Returns the datum associated with the GPS coordinate. Value is derived from EXIF GPS metadata (tag 0x0012).
getGpsTags( ) returns java.util.HashMap
Used to parse EXIF metadata and return a list of key/value pairs associated with GPS metadata. Values can be Strings, Integers, or raw Byte Arrays.
getHeight( ) returns int
Returns the height of the image, in pixels.
getHistogram( ) returns java.util.ArrayList
Returns an array with 4 histograms: red, green, blue, and average
        ArrayList histogram = image.getHistogram();
        int[] red = histogram.get(0);
        int[] green = histogram.get(1);
        int[] blue = histogram.get(2);
        int[] average = histogram.get(3);
    
getIIOMetadata( ) returns javax.imageio.metadata.IIOMetadata
Returns the raw, javax.imageio.metadata.IIOMetadata associated with this image. You can iterate through the metadata using an xml parser like this:
    IIOMetadata metadata = image.getMetadata().getIIOMetadata();
    for (String name : metadata.getMetadataFormatNames()) {
        System.out.println( "Format name: " + name );
        org.w3c.dom.Node metadataNode = metadata.getAsTree(name);
        System.out.println(javaxt.xml.DOM.getNodeValue(metadataNode));
    }
   
getImage( ) returns java.awt.Image
Returns a java.awt.Image copy of the current image.
getInputFormats( ) returns String[]
Used to retrieve a list of supported input (read) formats.
getIptcData( ) returns byte[]
Returns the raw IPTC byte array (marker 0xED).
getIptcTags( ) returns java.util.HashMap
Used to parse IPTC metadata and return a list of key/value pairs found in the metadata. You can retrieve specific IPTC metadata values like this:
    javaxt.io.Image image = new javaxt.io.Image("/temp/image.jpg");
    java.util.HashMap<Integer, String> iptc = image.getIptcTags();
    System.out.println("Date: " + iptc.get(0x0237));
    System.out.println("Caption: " + iptc.get(0x0278));
    System.out.println("Copyright: " + iptc.get(0x0274));
   
getMetadataByTagName( String tagName ) returns javax.imageio.metadata.IIOMetadataNode[]
Returns a list of IIOMetadataNodes for a given tag name (e.g. "Chroma", "Compression", "Data", "Dimension", "Transparency", etc).
  //Print unknown tags
    for (IIOMetadataNode unknownNode : metadata.getMetadataByTagName("unknown")){
        int marker = Integer.parseInt(javaxt.xml.DOM.getAttributeValue(unknownNode, "MarkerTag"));
        System.out.println(marker + "\t" + "0x" + Integer.toHexString(marker));
    }
   
getOutputFormats( ) returns String[]
Used to retrieve a list of supported output (write) formats.
getRenderedImage( ) returns java.awt.image.RenderedImage
Returns a java.awt.image.RenderedImage copy of the current image.
getUnknownTags( int MarkerTag ) returns javax.imageio.metadata.IIOMetadataNode[]
Returns a list of "unknown" IIOMetadataNodes for a given MarkerTag. You can use this method to retrieve EXIF, IPTC, XPM, and other format specific metadata. Example:
    byte[] IptcData = (byte[]) metadata.getUnknownTags(0xED)[0].getUserObject();
    byte[] ExifData = (byte[]) metadata.getUnknownTags(0xE1)[0].getUserObject();
   
getWidth( ) returns int
Returns the width of the image, in pixels.
resize( int Width, int Height ) returns void
Used to resize an image. Does NOT automatically retain the original aspect ratio.
resize( int Width, int Height, boolean maintainRatio ) returns void
Used to resize an image. Provides the option to maintain the original aspect ratio (relative to the output width).
rotate( ) returns void
Used to automatically rotate the image based on the image metadata (EXIF Orientation tag).
rotate( double Degrees ) returns void
Used to rotate the image (clockwise). Rotation angle is specified in degrees relative to the top of the image.
rotateClockwise( ) returns void
Rotates the image 90 degrees clockwise
rotateCounterClockwise( ) returns void
Rotates the image -90 degrees
saveAs( String PathToImageFile ) returns void
Exports the image to a file. Output format is determined by the output file extension.
saveAs( java.io.File OutputFile ) returns void
Exports the image to a file. Output format is determined by the output file extension.
setBackgroundColor( int r, int g, int b ) returns void
Used to set the background color. Creates an image layer and inserts it under the existing graphic. This method should only be called once.
setColor( int x, int y, java.awt.Color color ) returns void
Used to set the color (ARGB value) for a specific pixel in the image. Note that input x,y values are relative to the upper left corner of the image, starting at 0,0.
setCorners( float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3 ) returns void
Used to skew an image by updating the corner coordinates. Coordinates are supplied in clockwise order starting from the upper left corner.
setHeight( int Height ) returns void
Resizes the image to a given height. The original aspect ratio is maintained.
setIIOMetadata( javax.imageio.metadata.IIOMetadata metadata ) returns void
Used to set/update the raw javax.imageio.metadata.IIOMetadata associated with this image.
setOpacity( double percent ) returns void
setOutputQuality( double percentage ) returns void
Used to set the output quality/compression ratio. Only applies when creating JPEG images. Applied only when writing the image to a file or byte array.
setWidth( int Width ) returns void
Resizes the image to a given width. The original aspect ratio is maintained.
sharpen( ) returns void
Used to sharpen the image using a 3x3 kernal.
trim( ) returns void
Used to remove excess pixels around an image by cropping the image to its "true" extents. Crop bounds are determined by finding the first non-null or non-black pixel on each side of the image.
trim( int r, int g, int b ) returns void
Used to remove excess pixels around an image by cropping the image to its "true" extents. Crop bounds are determined by finding pixels that *don't* match the input color. For example, you can trim off excess black pixels around an image by specifying an rgb value of 0,0,0. Similarly, you can trim off pure white pixels around an image by specifying an rgb value of 255,255,255. Note that transparent pixels are considered as null values and will be automatically trimmed from the edges.