JavaXT
|
|||||||||||||||||||||||||||||||||||||||||||||||
Image ClassUsed to open, resize, rotate, crop and save images.
ConstructorsPropertiesInputFormats
OutputFormats
Public MethodssetBackgroundColor( 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. getInputFormats( ) returns String[] Used to retrieve a list of supported input (read) formats. getOutputFormats( ) returns String[] Used to retrieve a list of supported output (write) formats. addText( String text, int x, int y ) returns void Used to add text to the image at a given position.
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.
addText( String text, int x, int y, Font font, int r, int g, int b ) returns void Used to add text to the image at a given position.
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. setColor( int x, int y, 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. getColor( int x, int y ) returns 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. getHistogram( ) returns java.util.ArrayList<int[]> Returns an array with 4 histograms: red, green, blue, and average
ArrayList<int[]> histogram = image.getHistogram(); int[] red = histogram.get(0); int[] green = histogram.get(1); int[] blue = histogram.get(2); int[] average = histogram.get(3); addImage( 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. rotate( double Degrees ) returns void Used to rotate the image (clockwise). Rotation angle is specified in degrees relative to the top of the image. rotate( ) returns void Used to automatically rotate the image based on the image metadata (e.g. EXIF Orientation tag) setWidth( int Width ) returns void Resizes the image to a given width. The original aspect ratio is maintained. setHeight( int Height ) returns void Resizes the image to a given height. The original aspect ratio is maintained. 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.
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. 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() 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. 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). crop( int x, int y, int width, int height ) returns void Used to crop/subset the current image. copyRect( int x, int y, int width, int height ) returns Image Returns a copy of the image at a given rectangle. 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. getBufferedImage( ) returns BufferedImage Returns the java.awt.image.BufferedImage represented by the current image. getRenderedImage( ) returns java.awt.image.RenderedImage Returns a java.awt.image.RenderedImage copy of the current image. getBufferedImage( int width, int height, boolean maintainRatio ) returns 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. 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. setOutputQuality( float quality ) 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. Accepts values between 0-1. Also accepts values between 1-100. If the latter, it divides the value by 100. equals( Object obj ) returns boolean Used to compare this image to another. Returns true if the all the pixels (ARGB values) match. See isSimilarTo() to compare similar images. isSimilarTo( Image image ) returns boolean Returns true if a given image is similar to (or equal to) this image. Unlike the equals() method which performs an exact match, this method performs a fuzzy match using perceptual hash values for the images. Returns true if the Hamming Distance between the two images is 0. isSimilarTo( Image image, int threshold ) returns boolean Returns true if a given image is similar to this image. Performs a fuzzy match using perceptual hash values for the images.
getHammingDistance( Image image ) returns int Returns the Hamming Distance between this image and a given image using perceptual hash values for the images. getPHash( ) returns long Returns a perceptual hash value for the image. Unlike traditional cryptographic hashes like SHA1, PHash is not sensitive to tiny variations in an image. This makes it ideal to find similar images.
getIIOMetadata( ) returns 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.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)); } setIIOMetadata( IIOMetadata metadata ) returns void Used to set/update the raw javax.imageio.metadata.IIOMetadata associated with this image. getIptcTags( ) returns HashMap<Integer, Object> 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)); getExifTags( ) returns HashMap<Integer, Object> 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. getGpsTags( ) returns HashMap<Integer, Object> 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. 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). getUnknownTags( int MarkerTag ) returns 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(); getMetadataByTagName( String tagName ) returns 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)); } Static MethodsgetAttributeValue( 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. |