Package com.day.image

Class Layer

java.lang.Object
com.day.image.Layer

public class Layer extends Object
The Layer class provides a simplified usage pattern for doing graphics rendering. As such the Layer class forms the basis of Graphics Engine. The implementation is closely based on the BufferedImage class of the Java2D API. For this reason the drawing idiom closely represents the Java2D API in which you first define the line style and paint mode of the object to be drawn in the second step.

Classification of methods

Layer modification   The layer modifying operations change the complete layer and comprise operations such as rotating, blur, etc. The layer modifying operations are flatten(java.awt.Color), rotate(double), resize(int, int), crop(java.awt.geom.Rectangle2D), emboss(com.day.image.Layer, int, int, int), xForm(int, int, int, int, int, int, int, int, boolean), colorize(java.awt.Color, java.awt.Color), monotone(java.awt.Color), multitone(java.awt.Color[]), blur(double, double, int, double, double), sharpen(float, float), xFormColors(double[][], double[], boolean), replaceColor(long, long, boolean), adjust(int, float).
Layer copying   The layer copying operations copy parts - color channels or regions - or complete other layers onto/into the current layer. The layer copying operations comprise merge(com.day.image.Layer), blit(com.day.image.Layer, int, int), copyChannel(com.day.image.Layer, int, int), colorMask(com.day.image.Layer, java.awt.Color)
Drawing modifiers   The drawing modifiers modify the behaviour of subsequent drawing and filling operations in respect to paint, stroke, etc. The drawing modifiers are setPaint(java.awt.Paint), setStroke(java.awt.Stroke), setLineStyle(com.day.image.LineStyle), setComposite(java.awt.Composite), setTransform(java.awt.geom.AffineTransform) and setLuminanceSystem(com.day.image.Layer.LuminanceSystem).
Drawing and filling   The drawing and filling operations do just what they are meant to do : draw or fill geometrical figures or shapes. The drawing and filling operations comprise drawText(int, int, int, int, java.lang.String, com.day.image.font.AbstractFont, int, double, int), fillRect(java.awt.geom.Rectangle2D), drawRect(java.awt.geom.Rectangle2D), drawLine(float, float, float, float), drawPolyLine(float[][]), drawEllipse(float, float, float, float), fillEllipse(float, float, float, float), drawSegment(float, float, float, float, double, double), drawSector(float, float, float, float, double, double), fillSector(float, float, float, float, double, double), draw(java.awt.Shape), fill(java.awt.Shape).
Miscellaneous   These methods do miscellaneous operations not classifiable above : getPixel(int, int), setPixel(int, int, long), getBoundingBox(), getBoundingBox(), getBackgroundColor(), floodFill(java.awt.Color, int), floodFill(java.awt.Color, int)

Coordinate system

Layer coordinates are specified using the origin (0,0) in the top left corner, horizontally spanning to the right and vertically spanning down. This is the same usage as in the Java 2D API which is used to implement the Layer class.

The Java2D API support floating point coordinates, for this reason all the Layer methods support floating point coordinates, too. This fact is of essential use in case of affine transformation applied to the drawing.

Colors

For each method that takes a numeric value as a color value - such as setPixel(int, int, long) - or returns a numeric color value - such as getPixel(int, int) - this number is a 32bit unsigned integer number, which encodes 8bits per color value and the alpha channel value. The colors are all defined to be RGB colors in the standard sRGB color space.

Example: the value 0xff60c0f0 defines the alpha channel to 0xff, the red channel to 0x60, the green channel to 0xc0 and the blue channel to 0xf0.

The methods taking a Paint object as a parameter you may pass a Color object which you define - amongst others - with the constructor taking the 32bit integer value encoded as noted above ;
Paint col = new Color( 0xff6cc0f0, true );

Properties of Layer objects

x, y, width, height   The top, left corner of the layer as well as the width and height of the layer. The top, left corner coordinate is only used when merging or blitting layers, to support relative positioning of the layers. Also when writing the layer in GIF format, the top, left corner values are used.
bgcolor   The background color of the layer. The layer is filled with this color when being allocated. This is also the default color to flatten against.
transparency   The color in the image which is considered to be the transparent color. This value is only of use for GIF images, as JPG and PNG correctly account for the alpha channel values per pixel and create partially transparent pixels.
opacity   The opacity is used during layer merging to merge layers in partially transparent manner.
mimeType   This is the default MIME type of the layer. This is set from the image file if the layer is loaded from an image or defaults to "image/gif". This is used to write the image, if the image type parameter is missing.
quality   Will define some quality values in the future. This is not used yet.

Notes on J2SE 1.3

The Graphics Engine uses the new ImageIO API to read and write image files. Unfortunately this API is only avaiable with J2SE 1.4 though for some time an early access version called EA2 has been available for J2SE 1.3. The Graphics Engine library contains this EA2 ImageIO implementation which is only used if running in J2SE 1.3.

J2SE 1.3 contains a bug which prevents graphical applications from running correctly on Unix systems if no XServer is available. This is known as 'headless' operation mode and reported to Sun in Sun bug #4281163, support "headless" Java. The workaround is to have the PJA toolkit installed and starting the JVM with the following additional parameters :

  -Xbootclasspath/a:<lib>\pja.jar -Dawt.toolkit=com.eteks.awt.PJAToolkit \
  -Djava.awt.graphicsenv=com.eteks.java2d.PJAGraphicsEnvironment \
  -Djava2d.font.usePlatformFont=false
 
Since:
coati
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    The LuminanceSystem class encapsulates luminance factor values for greyscaling operations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Channel number to identify the alpha channel for diverse methods involving color channels, i.e.
    static final int
    Channel number to identify the blue color channel for diverse methods involving color channels, i.e.
    static final String
    Default MIME type for writing the image.
    Luminance factors for RGB in a Gamma 2.2 color space.
    static final int
    Channel number to identify the green color channel for diverse methods involving color channels, i.e.
    Luminance factors for RGB in a linear color space.
    Luminance factors for RGB in a color space for contemporary CRT phosphors according to Rec.
    static final int
    Channel number to identify the red color channel for diverse methods involving color channels, i.e.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Layer(int width, int height, Paint bground)
    Creates a Layer with the indicated dimensions and background paint.
    Layer(Layer src)
    Creates a new Layer by copying the image of the source layer and setting all properties to the exact same value they are set in the source layer.
    Creates a new Layer by wrapping the BufferedImage with the Layer properties.
    Creates a new Layer instance by loading an image from the InputStream.
    Layer(InputStream input, int idx)
    Creates a new Layer instance by loading the indexed image from the InputStream.
    Layer(InputStream input, int idx, Dimension max)
    Creates a new Layer instance by loading the indexed image from the InputStream.
    Layer(InputStream input, int idx, Dimension max, ImageReadParam params)
    Creates a new Layer instance by loading the indexed image from the InputStream.
    Creates a new Layer instance by loading an image from the InputStream.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    adjust(int brightness, float contrast)
    Adjust brightness and contrast of the image using the adjustments indicated : The brightness operand is a number in the range -255 ..
    void
    blit(Layer src, int dw, int dh)
    Copy a subimage from the given source layer to this layer.
    void
    blit(Layer src, int dx, int dy, int dw, int dh, int sx, int sy)
    Copy a subimage from the given source layer to this layer.
    void
    blur(double radius, double scale, int flags, double gran, double maxdata)
    Blurs the picture in the layer using the values given.
    void
    colorize(Color darkcolor, Color brightcolor)
    Colorizes the layer, i.e.
    void
    colorMask(Layer src, Color col)
    Colorizes the identical pixel of the source and destination layer with the indicated color.
    void
    copyChannel(Layer src, int fromChannel, int toChannel)
    Copy the color or alpha channel from the source the same or another color or alpha channel in this layer.
    void
    Get the subimage indicated by the rectangle from the layer.
    void
    Releases as much resources as possible.
    void
    Draws the layer into another graphics element, for example another image or a canvas.
    void
    draw(Shape shape)
    Draws (the outline of) the given shape.
    void
    drawEllipse(float cx, float cy, float a, float b)
    Draws an ellipse around the given center with the indicated horizontal and vertical radii.
    void
    drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
    Draws the image onto the layers image at the indicated position doing the image operation before drawing.
    void
    drawLine(float x1, float y1, float x2, float y2)
    Draws a straight line between the points (x1/y1) and (x2/y2) in the current stroke and paint mode applying the current composite.
    void
    drawPolyLine(float[][] points)
    Draws a connected lines of multiple points given in the points array.
    void
    Draws the outline of the given rectangle with the preset color and stroke obeying the current composite setting.
    void
    drawSector(float cx, float cy, float a, float b, double from, double extent)
    Draws an arc of the given ellipse with which is closed by drawing additional lines from the center point to the starting and ending points of the arc.
    void
    drawSegment(float cx, float cy, float a, float b, double from, double extent)
    Draws an arc of the given ellipse.
    int
    drawText(int x, int y, int width, int height, String text, AbstractFont font, int align, double cs, int ls)
    Render the given text string in the given font to the Layer using the attributes given.
    void
    emboss(Layer bump, int azimut, int elevation, int filtersize)
    Embosses the layer using the bump (if specified) and the light direction specified by aizmut and elevation.
    void
    fill(Shape shape)
    Fills (the area of) the given shape.
    void
    fillEllipse(float cx, float cy, float a, float b)
    Fills an ellipse around the given center with the indicated horizontal and vertical radii.
    void
    Fill the given rectangle with the layer defined as the temporary paint object.
    void
    According to the current paint and composite setting, the given rectangle is drawn onto the layer.
    void
    fillSector(float cx, float cy, float a, float b, double from, double extent)
    Filles a sector of the given ellipse with which is closed by drawing additional lines from the center point to the starting and ending points of the arc.
    void
    flatten(Color color)
    Adapt the alpha channel of the image so that each color value has its value multiplied with the alpha value.
    void
    Flips the layer horizontally.
    void
    Flips the layer vertically.
    void
    floodFill(Color fillColor, int blur)
    Floods the background with the new fill color.
    void
    floodFill(Color fillColor, int blur, Color bgColor)
    Starting from the four edges of the image towards the center, the method replaces background color by the fill color.
    Returns the background of the layer.
    Gets the background color of the image.
    Gets the bounding box of the image, that is the size of the rectangle spanning all pixels, that do not have the same color as the background color.
    Gets the bounding box of the image, that is the size of the rectangle spanning all pixels, that do not have the same color as the given color which is supposed to be the background color.
    Returns the rectangle spanned by the image.
    Returns the current Composite in the Graphics2D context.
    Returns the Graphics2D object used to draw into this layer.
    int
    Returns the height of the layer.
    Returns the image on which this layer is based.
    int
    Returns the index of image of this layer within the multi-image file from which this layer has been loaded.
    Returns the current Composite of this layer.
    Returns the MIME type of the image from which the layer has been loaded.
    int
    Returns the number of images in the source from where this layer has been loaded or -1 if the number of images is not known or the lay has not been loaded from an image file.
    float
    Gets the opacity of the layer.
     
    int
    getPixel(int x, int y)
    After checking whether the desired coordinate lies within the layer it gets the ARGB value out of storage and returns that value
    Returns the value of a single preference for the rendering algorithms.
     
    Returns the Color value of transparent pixels.
    int
    Returns the width of the layer.
    int
    Returns the left edge of the layer.
    int
    Returns the top edge of the layer.
    void
    Converts the color image into a grayscale image
    void
    merge(Layer layer)
    Merges a layer onto the current layer whereby obeying the layer's opacity level.
    void
    merge(Layer[] layers)
    Merges a number of layers onto the current layer whereby obeying each layers opacity level.
    void
    monotone(Color color)
    Monotonize the image with a base color other than black.
    void
    multitone(ColorCurve[] colorCurves)
    Colorize the image according to the color curves.
    void
    multitone(Color[] colors)
    Multitone an image.
    void
    reduceColors(int numColors)
    Reduces the number of colors of the image to the indicated number, doing easy 'nearest' color replacement based on a weighting algorithm.
    void
    replaceColor(long color1, long color2, boolean ignoreAlpha)
    Sets all pixels having color1 to color2.
    void
    resize(int width, int height)
    Resize the image scaling it by the scaling factor indicated by the new width and height parameters.
    void
    resize(int width, int height, boolean fast)
    Resize the image scaling it by the scaling factor indicated by the new width and height parameters.
    void
    rotate(double degrees)
    Rotates the layer by the given angle in degrees in clockwise direction.
    void
    Sets the background of the layer.
    void
    Set the background color to the indicated value.
    void
    Sets the drawing composite for drawing and filling operations to the composite given.
    void
    setLayerComposite(Composite layerComposite)
    Sets the AlphaComposite used for merging this layer onto other layers.
    void
    Sets both the paint and the stroke for the next draw and fill operations.
    void
    Define the set of color weights to use in luminance definition
    void
    setMimeType(String mimeType)
    Sets the MIME type of the image, which is used when writing the image with no explicite MIME type setting.
    void
    setOpacity(float opacity)
    Sets the opacity of the layer.
    void
    setPaint(Paint paint)
    Sets the paint for subsequent draw and fill operations.
    void
    setPixel(int x, int y, long color)
    After checking whether the pixel lies within the layer, its color is set to the desired value.
    void
    Sets the value of a single preference for the rendering algorithms.
    void
    setStroke(Stroke stroke)
    Sets the line stroke to use for the subsequent draw operation.
    void
    Sets the affine transformation applied to all of the drawing and filling operations.
    void
    setTransparency(Color transparency)
    Sets the Color value of pixels to be regarded transparent.
    void
    setX(int x)
    Sets the left edge of the layer.
    void
    setY(int y)
    Sets the top edge of the layer.
    void
    sharpen(float amount, float radius)
    Sharpens the image by applying a convolution operation which involves ehancing the center of a kernel.
    Convert the Layer to some string representation for intelligent display.
    boolean
    write(String mimeType, double quality, OutputStream outStream)
    Write the image to the given OutputStream using the desired MIME type.
    void
    xForm(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, boolean crop)
    Distorts the layer along a 4-edged shape.
    void
    xFormColors(double[][] matrix, double[] vector, boolean crop)
    Recombines the channels of the layer.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Layer

      public Layer(int width, int height, Paint bground)
      Creates a Layer with the indicated dimensions and background paint. The background paint may be any valid Paint implementation but will usually be a simple Color instance.

      The remaining properties of the layer are set to their default value. The origin is set to zero, the image type is GIF and the transparency color is not set.

      Note, that the background Paint is painted into the newly created layer. If you later set the background Paint to something else and resize the layer or merge it with other layer(s) some part of the layer will still have the old background color.

      Parameters:
      width - Width of the new layer. The minimum width of a layer is 1.
      height - Height of the new layer. The minimum height of a layer is 1.
      bground - The background paint of the new layer. This may be null in which case the background is assumed to be in transparent white.
      Throws:
      IllegalArgumentException - if either the width or the height are specified lower than 1.
    • Layer

      public Layer(InputStream input) throws IOException, IIOException
      Creates a new Layer instance by loading an image from the InputStream.

      The width and height are set to the values of the image, while the other values are set to their respective default values as defined in the class comment above.

      This constructor is equivalent to calling the Layer(InputStream, int) constructor with an index value or zero.

      Parameters:
      input - The InputStream to read the image data from
      Throws:
      NullPointerException - if the InputStream is null.
      IOException - if reading from the stream throws such an exception.
      IIOException - if decoding the image fails
    • Layer

      public Layer(InputStream input, Dimension max) throws IOException, IIOException
      Creates a new Layer instance by loading an image from the InputStream.

      The width and height are set to the values of the image, while the other values are set to their respective default values as defined in the class comment above.

      if max is given, the loaded image will not be bigger than the given dimensions. eg: if the image is 1000x400 and the constraints are 500x500, the resulting layer will be 500x200. This constructor is equivalent to calling the Layer(InputStream, int, Dimension) constructor with an index value or zero.

      Parameters:
      input - The InputStream to read the image data from
      max - optional constraint for the maximal dimensions.
      Throws:
      NullPointerException - if the InputStream is null.
      IOException - if reading from the stream throws such an exception.
      IIOException - if decoding the image fails
    • Layer

      public Layer(InputStream input, int idx) throws IOException, IIOException
      Creates a new Layer instance by loading the indexed image from the InputStream.

      The width and height are set to the values of the image, while the other values are set to their respective default values as defined in the class comment above.

      Parameters:
      input - The InputStream to read the image data from
      idx - The zero-based index of the image in the image data stream. The first image has index zero. This must not be a negative number.
      Throws:
      NullPointerException - if the InputStream is null.
      IndexOutOfBoundsException - If idx is higher than the index of the last image in the image file.
      IOException - if reading from the stream throws such an exception.
      IIOException - if decoding the image fails
    • Layer

      public Layer(InputStream input, int idx, Dimension max) throws IOException, IIOException
      Creates a new Layer instance by loading the indexed image from the InputStream.

      The width and height are set to the values of the image, while the other values are set to their respective default values as defined in the class comment above. if max is given, the loaded image will not be bigger than the given dimensions. eg: if the image is 1000x400 and the constraints are 500x500, the resulting layer will be 500x200.

      Parameters:
      input - The InputStream to read the image data from
      idx - The zero-based index of the image in the image data stream. The first image has index zero. This must not be a negative number.
      max - optional constraints for the maximal dimensions.
      Throws:
      NullPointerException - if the InputStream is null.
      IndexOutOfBoundsException - If idx is higher than the index of the last image in the image file.
      IOException - if reading from the stream throws such an exception.
      IIOException - if decoding the image fails
    • Layer

      public Layer(InputStream input, int idx, Dimension max, ImageReadParam params) throws IOException, IIOException
      Creates a new Layer instance by loading the indexed image from the InputStream.

      The width and height are set to the values of the image, while the other values are set to their respective default values as defined in the class comment above. if max is given, the loaded image will not be bigger than the given dimensions. eg: if the image is 1000x400 and the constraints are 500x500, the resulting layer will be 500x200.

      Parameters:
      input - The InputStream to read the image data from
      idx - The zero-based index of the image in the image data stream. The first image has index zero. This must not be a negative number.
      max - optional constraints for the maximal dimensions.
      params - an instance of ImageReadParam.
      Throws:
      NullPointerException - if the InputStream is null.
      IndexOutOfBoundsException - If idx is higher than the index of the last image in the image file.
      IOException - if reading from the stream throws such an exception.
      IIOException - if decoding the image fails
    • Layer

      public Layer(Layer src)
      Creates a new Layer by copying the image of the source layer and setting all properties to the exact same value they are set in the source layer.
      Parameters:
      src - The layer to copy
      Throws:
      NullPointerException - if the source layer is null.
    • Layer

      public Layer(BufferedImage image)
      Creates a new Layer by wrapping the BufferedImage with the Layer properties. Note that this really is a wrapping constructor and not a copy constructor. That is if you keep drawing into the original image, you get a mixed result.
      Parameters:
      image - The BufferedImage to wrap as a Layer.
      Throws:
      NullPointerException - if the image is null.
  • Method Details

    • write

      public boolean write(String mimeType, double quality, OutputStream outStream) throws IIOException, IOException
      Write the image to the given OutputStream using the desired MIME type. If the MIME type is empty or null, we use the MIME type of the layer.

      The quality parameter is used to define the compression level of JPEG image creation, if JPEG output is desired as per the MIME type. The quality value must be in the range 0.0 .. 1.0 inclusive. Any value outside this range results in the default compression factor 0.82 being used.

      For GIF images the colors will be reduced according to the quality argument. If the argument is missing, at most 256 colors will be in the image or as much as need be.

      Note that specifying the MIME type for the image type is simply used to decide on the output format to use for writing. Especially the method is not able set any Content-Type headers whatsoever.

      The OutputStream is neither flushed nor closed at the end. It is the sole responsibilty of the client of this method to do so.

      Parameters:
      mimeType - MIME type to use for writing. If empty or null the MIME type of the image will be used. As a last fall back the default MIME type as per DEFAULT_MIME_TYPE is used.
      quality - Defines the JPEG compression quality (0.0 .. 1.0) or the numbers of colors to use for the GIF image.
      outStream - OutputStream to use to write the layer.
      Returns:
      true if the layer could be written, else false is returned.
      Throws:
      IllegalArgumentException - if a mimeType is specified either as a parameter or as the layer's image type, which is not supported for writing by the ImageIO system.
      NullPointerException - if the OutputStream is null.
      IIOException - we get from the ImageIO Library we use.
      IOException - we get from writing to the OutputStream.
    • dispose

      public void dispose()
      Releases as much resources as possible. This method is called when the layer is not intended to be used any more.

      Note that using the layer object again after calling this method results in unexpected behaviour and at least throwing of NullPointerExceptions.

    • merge

      public void merge(Layer layer)
      Merges a layer onto the current layer whereby obeying the layer's opacity level. The size of the current Layer is adapted to the compound size of both layers merged.
      Parameters:
      layer - the Layers to merge onto this one. If null this layer is not changed.
    • merge

      public void merge(Layer[] layers)
      Merges a number of layers onto the current layer whereby obeying each layers opacity level. The layers are merged in the sequence the are listed in the array. The size of the current Layer is adapted to the compound size of all layers merged.

      Each layer is painted over the already painted layers according to the opacity and composite set on the layer to be painted. If the getLayerComposite() is not a AlphaComposite, the opacity is ignored.

      This method is conservative in that it is a null operation if the layers is null or empty.

      Parameters:
      layers - the list of Layers to merge onto this one.
    • blit

      public void blit(Layer src, int dw, int dh)
      Copy a subimage from the given source layer to this layer. The copied image is hooked in the top left corner of the Layer.
      Parameters:
      src - the source Layer to copy from
      dw - the width of reactangle to copy
      dh - the height of the rectangle to copy.
      See Also:
    • blit

      public void blit(Layer src, int dx, int dy, int dw, int dh, int sx, int sy)
      Copy a subimage from the given source layer to this layer. The source rectangle is fully specified by its origin, width and height while the destination position of the top left corner is also given.
      Parameters:
      src - the source Layer to copy from
      dx - the left edge of the destination area in this layer
      dy - the top edge of the destination area in this layer
      dw - the width of reactangle to copy
      dh - the height of the rectangle to copy.
      sx - the left edge of the source area in the source layer
      sy - the top edge of the source area in the source layer
    • copyChannel

      public void copyChannel(Layer src, int fromChannel, int toChannel)
      Copy the color or alpha channel from the source the same or another color or alpha channel in this layer. Nothing is done, if the method would do an identity copy, that is l.copyChannel(null, c, c) will do nothing.
      Parameters:
      src - the source layer for the channel copy, if null this is used as the src.
      fromChannel - channel to copy from the the source layer. If negative, the alpha channel will be copied
      toChannel - channel in this layer to copy the fromChannel into. If negative the same channel as fromChannel will be used.
      Throws:
      IndexOutOfBoundsException - if the channel number is higher than number of available channels in either the source or this layer.
    • colorMask

      public void colorMask(Layer src, Color col)
      Colorizes the identical pixel of the source and destination layer with the indicated color. This can be used to produce a transparent text over a background image.
      Parameters:
      src - the source layer for the masking operation or null this.
      col - the color to set for identical pixels. If null opaque black is used.
    • flatten

      public void flatten(Color color)
      Adapt the alpha channel of the image so that each color value has its value multiplied with the alpha value. For each pixel not set the indicated color is set.

      The DST_OVER composite paints the background only as much as the alpha channel of the layer pixels allows also respecting the alpha value of the background color !!

      Parameters:
      color - The color to use for unlit pixels. Set to a negative value to use the background color of the layer.
    • rotate

      public void rotate(double degrees)
      Rotates the layer by the given angle in degrees in clockwise direction.
      Parameters:
      degrees - the angle to rotate the layer by. Usually this angle should be in the range 0-360�.
    • flipHorizontally

      public void flipHorizontally()
      Flips the layer horizontally.
    • flipVertically

      public void flipVertically()
      Flips the layer vertically.
    • resize

      public void resize(int width, int height)
      Resize the image scaling it by the scaling factor indicated by the new width and height parameters. If the aspect ration of the existing layer should be kept, the new width and height values should be set accordingly.
      Parameters:
      width - the new width of the layer. Set to 0 or a negative value to keep the current width.
      height - the new height of the layer. Set to 0 or a negative value to keep the current height.
    • resize

      public void resize(int width, int height, boolean fast)
      Resize the image scaling it by the scaling factor indicated by the new width and height parameters. If the aspect ration of the existing layer should be kept, the new width and height values should be set accordingly.
      Parameters:
      width - the new width of the layer. Set to 0 or a negative value to keep the current width.
      height - the new height of the layer. Set to 0 or a negative value to keep the current height.
      fast - if set to true a faster resizing algorithm is used but with poorer detail.
    • crop

      public void crop(Rectangle2D rect)
      Get the subimage indicated by the rectangle from the layer. The subimage is simply cut out the bigger one.
      Parameters:
      rect - the rectangle definiing the part of the image to cut out
    • emboss

      public void emboss(Layer bump, int azimut, int elevation, int filtersize)
      Embosses the layer using the bump (if specified) and the light direction specified by aizmut and elevation.
      NOTE: This implementation is a copy of the existing rgbaLayer routine. It may therefore not be very fast. But it works the same as the corresponding ECMA routine ;-)
      Parameters:
      bump - the bump layer to emboss this layer with. If null this layer itself will also be used as the bump.
      azimut - the light direction azimut. Specify a negative value to get the default value of 30.
      elevation - the light direction elevation. Specify a negative value to get the default value of 30.
      filtersize - the filtersize for the embossing. Specify a negative value to get the default value of 3.
    • xForm

      public void xForm(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, boolean crop)
      Distorts the layer along a 4-edged shape. The transformation of the rectangle may lead to a rectangle of a different size. Depending on the crop parameter, the size of the layer is adapted to the new size or not. If crop==true, the layer's size is either enlarged or made smaller depending on the bounding box of the transformed layer.

      This method internally uses the DistortOp class to calculate the transformed layer. Therefore the same warning about memory usage applies to this method as does to the DistortOp class.

      Parameters:
      x1 - x-coordinate of top left corner of transformed rectangle
      y1 - y-coordinate of top left corner of transformed rectangle
      x2 - x-coordinate of top right corner of transformed rectangle
      y2 - y-coordinate of top right corner of transformed rectangle
      x3 - x-coordinate of bottom left corner of transformed rectangle
      y3 - y-coordinate of bottom left corner of transformed rectangle
      x4 - x-coordinate of bottom right corner of transformed rectangle
      y4 - y-coordinate of bottom right corner of transformed rectangle
      crop - true of the layer should be adapted to the bounding of the transformed rectangle.
    • grayscale

      public void grayscale()
      Converts the color image into a grayscale image
    • colorize

      public void colorize(Color darkcolor, Color brightcolor)
      Colorizes the layer, i.e. map the brightness of the image onto the gradient from darkcolor to brightcolor.
      Parameters:
      darkcolor - the dark start color for the colorization. If negative 0xff000000 (black) will be used.
      brightcolor - the bright end color for the colorization. If negative 0xffffffff (white) will be used.
    • monotone

      public void monotone(Color color)
      Monotonize the image with a base color other than black. This method is equivalent to calling multitone(new Color[]{ color }).
      Parameters:
      color - Color to use as the base for the monotonized image
      Throws:
      NullPointerException - if the color value is null.
    • multitone

      public void multitone(Color[] colors)
      Multitone an image. The luminance scaled image is applied the listed colors in order to get the multitoned image result.

      Note that monotone(Color) is the single color special case of multitone.

      This method does not yet work as expected

      Parameters:
      colors - The colors to apply.
      Throws:
      NullPointerException - if the colors array or any of the elements in the array is null.
      IllegalArgumentException - if the colors array is empty
    • multitone

      public void multitone(ColorCurve[] colorCurves)
      Colorize the image according to the color curves. This operation is similar to the Photohop Duplex operation where you define a number of colors and optional tone curves.
      Parameters:
      colorCurves - The color curves to use in the MultitoneOp filter.
      See Also:
    • blur

      public void blur(double radius, double scale, int flags, double gran, double maxdata)
      Blurs the picture in the layer using the values given. Optionally only one of the color channels is blurred while all the others remain untouched. This method is simply a reimplementation of the ECMA method using the ConvolveOp class of the Java 2D API. Maybe we should specify the matrix better ?
      Parameters:
      radius - (default:1)
      scale - (default:1)
      flags - (default:all channels) - not used at the moment
      gran - (default:1)
      maxdata - (default:255)
    • sharpen

      public void sharpen(float amount, float radius)
      Sharpens the image by applying a convolution operation which involves ehancing the center of a kernel. Each element of the convolution matirx is set to -1, while the center - which is the source pixel - is set to the negative sum of all the other elements plus the given percentage amount of that sum. That is, the pixel is enhanced relativ to the neighbours.
      Parameters:
      amount - Center enhancement in percent in the range 0 .. 1.0
      radius - Size of the convolution matrix. The size is rounded to and integral matrix edge according to edge = int(2 * (radius + 1)). That is the minimum matrix size is guaranteed to be 1, which has no effect whatsoever. Allowed range for this value is 0.5 .. 10.0
    • xFormColors

      public void xFormColors(double[][] matrix, double[] vector, boolean crop)
      Recombines the channels of the layer. According to matrix4obj and vector4obj the channels (alpha, red, green, blue) of the layer are recombined and possibly scaled.
      Parameters:
      matrix - 4x4 matrix to multiply to the vector of channel values of each pixel
      vector - array of 4 elements to add to each resulting value got from the multiplication.
      crop - default true
    • replaceColor

      public void replaceColor(long color1, long color2, boolean ignoreAlpha)
      Sets all pixels having color1 to color2. The alpha channel value is only touched if ignoreAlpha is not set.
      Parameters:
      color1 - Color identifying pixels to be modified
      color2 - New color of those pixels
      ignoreAlpha - Set to true to not touch the alpha channel of the pixels.
    • adjust

      public void adjust(int brightness, float contrast)
      Adjust brightness and contrast of the image using the adjustments indicated :
      • The brightness operand is a number in the range -255 .. 255 where larger valus make the image brighter and lower values darken the image. A value of 0 does not change the brightness
      • The contrast operand is a positive float indicating the contrast enhancement. A value of 1.0 does not change the contrast. Values less than 1.0 lower the contrast while values higher than 1.0 enhance the contrast.
      The operation involved calculates the following value for each color of each pixel (the alpha channel is not modified) :
      destination = ( source * contrast ) + brightness
      The result is clipped to the range 0..255.
      Parameters:
      brightness - The brightness operand in the range -255 .. 255
      contrast - The contrast factor in the rang 0.0f .. infinity
    • reduceColors

      public void reduceColors(int numColors)
      Reduces the number of colors of the image to the indicated number, doing easy 'nearest' color replacement based on a weighting algorithm.
      Parameters:
      numColors - The number of colors to reduce the current image to.
    • setPaint

      public void setPaint(Paint paint)
      Sets the paint for subsequent draw and fill operations. In its simplest case the paint will be a color to paint, but it can be any Paint implementations such as GradientPaint.

      The paint setting remains active until changed by the next setLineStyle() or setPaint() call.

    • getPaint

      public Paint getPaint()
    • setStroke

      public void setStroke(Stroke stroke)
      Sets the line stroke to use for the subsequent draw operation. A stroke defines how the outline of a shape is drawn, e.g. solid, dashed, etc., and how the lines are terminated or interconnected.

      The stroke setting remains active until changed by the next setLineStyle() or setStroke() call.

    • getStroke

      public Stroke getStroke()
    • setLineStyle

      public void setLineStyle(LineStyle lineStyle)
      Sets both the paint and the stroke for the next draw and fill operations.

      The paint and stroke settings remain active until changed by the next setLineStyle() or setPaint() or setStroke() call.

    • setComposite

      public void setComposite(Composite composite)
      Sets the drawing composite for drawing and filling operations to the composite given. Most commonly the composite will be one of the predefined AlphaComposite implementations.
      Parameters:
      composite - The composite to set for the drawing operations.
      Throws:
      NullPointerException - if composite is null.
    • getComposite

      public Composite getComposite()
      Returns the current Composite in the Graphics2D context.
      Returns:
      the current Graphics2D Composite, which defines a compositing style.
    • setTransform

      public void setTransform(AffineTransform transfrom)
      Sets the affine transformation applied to all of the drawing and filling operations. Setting the affine transformation this way you can apply rotation, resizing and combinations thereof to single objects to be drawn instead of having to rotate or resize the complete layer.
      Parameters:
      transfrom - The affine transformation to apply to all drawing and filling operations when operating on the layer.
    • setLuminanceSystem

      public void setLuminanceSystem(Layer.LuminanceSystem system)
      Define the set of color weights to use in luminance definition
      Parameters:
      system - The luminance vector to use.
      See Also:
    • setRenderingHint

      public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
      Sets the value of a single preference for the rendering algorithms. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process. Refer to the RenderingHints class for definitions of some common keys and values.
      Parameters:
      hintKey - the key of the hint to be set.
      hintValue - the value indicating preferences for the specified hint category.
    • getRenderingHint

      public Object getRenderingHint(RenderingHints.Key hintKey)
      Returns the value of a single preference for the rendering algorithms. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process. Refer to the RenderingHints class for definitions of some common keys and values.
      Parameters:
      hintKey - the key corresponding to the hint to ge
      Returns:
      an object representing the value for the specified hint key. Some of the keys and their associated values are defined in the RenderingHints class.
    • drawText

      public int drawText(int x, int y, int width, int height, String text, AbstractFont font, int align, double cs, int ls)
      Render the given text string in the given font to the Layer using the attributes given. Use the default values given for unspecified values.

      If the width of the text box is set to some value other than zero, the text is broken to fit lines of the given length. The line breaking algorithm breaking algorithm breaks on whitespace (blank, tab), carriage return and linefeed (CR/LF) in any combination as well as on other characters such as hyphens.

      If the text contains carriage return and/or linefeed characters, the text is broken into several lines, regardless of whether the text would be broken because of the text box width setting.

      The layer may be enlarged to accomodate for the space needed for the text to be drawn. This is not the same behaviour as standard Java2D text drawing, where the text is clipped at the edges of the image.

      Parameters:
      x - left edge of the text box relative to the layer.
      y - top edge of the text box relative to the layer.
      width - maximum width of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributes
      height - maximum height of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributes
      text - the text string to draw
      font - the font to render the text string
      align - alignment, rotation and TrueType attributes for the text. Use AbstractFont.ALIGN_LEFT as default value.
      cs - extra intercharacter spacing. Use 0 as default value to not add additional space.
      ls - extra line spacing. Use 0 as default value to not add additional space.
      Returns:
      the number of text lines drawn to the layer
      Throws:
      NullPointerException - if either the text or the font argument is null.
      IllegalArgumentException - if either x or y are negative.
      See Also:
    • fillRect

      public void fillRect(Rectangle2D rect)
      According to the current paint and composite setting, the given rectangle is drawn onto the layer. If the rect parameter is null, the entire layer is filled with the paint.

      The edges of the rectangle drawn are defined as in Java2D, that is the left edge is x, the right edge is x+width-1, the top edge is y and the bottom edge is y+width-1.

      Parameters:
      rect - the rectangle to paint onto the layer. If set to null, the entire layer will be filled with that color.
    • fillRect

      public void fillRect(Layer src, Rectangle2D rect)
      Fill the given rectangle with the layer defined as the temporary paint object. This obeys the composite setting, but ignores the current paint setting as the layer is taken as the paint. After the method has finished the current paint is set again.
      Parameters:
      src - the source Layer to use. If this is the same as src, nothin happens.
      rect - the rectangle to paint onto the layer. If set to null, the entire layer will be filled with that color.
      Throws:
      NullPointerException - if src is null.
    • drawRect

      public void drawRect(Rectangle2D rect)
      Draws the outline of the given rectangle with the preset color and stroke obeying the current composite setting. If rect is null, this draws the outline on the edges of the layer.

      The edges of the rectangle drawn are defined as in Java2D, that is the left edge is x, the right edge is x+width, the top edge is y and the bottom edge is y+width.

      Parameters:
      rect - the rectangle to draw onto the layer. If set to null, the entire layer will be surrounded with a border line.
    • drawLine

      public void drawLine(float x1, float y1, float x2, float y2)
      Draws a straight line between the points (x1/y1) and (x2/y2) in the current stroke and paint mode applying the current composite.
      Parameters:
      x1 - The x coordinate of the starting point
      y1 - The y coordinate of the starting point
      x2 - The x coordinate of the ending point
      y2 - The y coordinate of the ending point
    • drawPolyLine

      public void drawPolyLine(float[][] points)
      Draws a connected lines of multiple points given in the points array. Each entry in the array contains of a x/y coordinate pair denoting one point in the line.
      Parameters:
      points - Array of x/y coordinate pairs. The array must consist of at least two entries, each entry containing at least two elements where the first element is interpreted as the x- and the second element is interpreted as the y-coordinate of that entry's point.
    • drawEllipse

      public void drawEllipse(float cx, float cy, float a, float b)
      Draws an ellipse around the given center with the indicated horizontal and vertical radii. The ellipse is drawn filling a rectangle that is twice the vertical radius high and twice the horizontal radius wide. The center of this rectangle is designated by the center coordinates. To draw a circle define the horizontal and vertical radius to be the same value.
      Parameters:
      cx - The x coordinate of the ellipse center
      cy - The y coordinate of the ellipse center
      a - The horizontal radius of the ellipse
      b - The vertical radius of the ellipse
    • fillEllipse

      public void fillEllipse(float cx, float cy, float a, float b)
      Fills an ellipse around the given center with the indicated horizontal and vertical radii. The ellipse is drawn filling a rectangle that is twice the vertical radius high and twice the horizontal radius wide. The center of this rectangle is designated by the center coordinates. To fill a circle define the horizontal and vertical radius to be the same value.
      Parameters:
      cx - The x coordinate of the ellipse center
      cy - The y coordinate of the ellipse center
      a - The horizontal radius of the ellipse
      b - The vertical radius of the ellipse
    • drawSegment

      public void drawSegment(float cx, float cy, float a, float b, double from, double extent)
      Draws an arc of the given ellipse. The base ellipse is defined as for drawEllipse(float, float, float, float), while only a segment of this ellipse is drawn. The segement is defined by the from and to angle denoting the starting and ending angle specified in degrees. The angle are defined such, that 0 degrees is the axis from the center to the right edge and positive angles turn counter clockwise.
      Parameters:
      cx - The x coordinate of the base ellipse center
      cy - The y coordinate of the base ellipse center
      a - The horizontal radius of the base ellipse
      b - The vertical radius of the base ellipse
      from - The starting angle as defined above
      extent - The angle the arc spans as defined above
    • drawSector

      public void drawSector(float cx, float cy, float a, float b, double from, double extent)
      Draws an arc of the given ellipse with which is closed by drawing additional lines from the center point to the starting and ending points of the arc. The base ellipse is defined as for of this ellipse is drawn. The segement is defined by the from and to angle denoting the starting and ending angle specified in degrees. The angle are defined such, that 0 degrees is the axis from the center to the right edge and positive angles turn counter clockwise.
      Parameters:
      cx - The x coordinate of the base ellipse center
      cy - The y coordinate of the base ellipse center
      a - The horizontal radius of the base ellipse
      b - The vertical radius of the base ellipse
      from - The starting angle as defined above
      extent - The angle the arc spans as defined above
    • fillSector

      public void fillSector(float cx, float cy, float a, float b, double from, double extent)
      Filles a sector of the given ellipse with which is closed by drawing additional lines from the center point to the starting and ending points of the arc. The base ellipse is defined as for drawEllipse(float, float, float, float), while only a segment of this ellipse is drawn. The segement is defined by the from and to angle denoting the starting and ending angle specified in degrees. The angle are defined such, that 0 degrees is the axis from the center to the right edge and positive angles turn counter clockwise.
      Parameters:
      cx - The x coordinate of the base ellipse center
      cy - The y coordinate of the base ellipse center
      a - The horizontal radius of the base ellipse
      b - The vertical radius of the base ellipse
      from - The starting angle as defined above
      extent - The angle the arc spans as defined above
    • draw

      public void draw(Shape shape)
      Draws (the outline of) the given shape. This is the generalized method of the different draw methods above. Using this method you can draw virtually anything you can possibly define in terms of a Shape.

      The Shape interface forms the basis for all geometrical figures such as circles, rectangles, lines but also text and even constructive area geometry.

      Parameters:
      shape - The Shape implementation object to draw
    • fill

      public void fill(Shape shape)
      Fills (the area of) the given shape. This is the generalized method of the different fill methods above. Using this method you can fill virtually anything you can possibly define in terms of a Shape.

      The Shape interface forms the basis for all geometrical figures such as circles, rectangles, lines but also text and even constructive area geometry.

      Parameters:
      shape - The Shape implementation object to draw
    • getPixel

      public int getPixel(int x, int y)
      After checking whether the desired coordinate lies within the layer it gets the ARGB value out of storage and returns that value
      Parameters:
      x - horizontal coordinate (0 at the left) of the pixel
      y - vertical coordinate (0 at the top) of the pixel
      Returns:
      0 if pixel lies outside the layer, else the ARGB value of the pixel.
    • setPixel

      public void setPixel(int x, int y, long color)
      After checking whether the pixel lies within the layer, its color is set to the desired value. If the pixel lies outside the layer no value is set and false is returned.
      Parameters:
      x - horizontal coordinate (0 at the left) of the pixel
      y - vertical coordinate (0 at the top) of the pixel
      color - ARGB value for the pixel
    • getBoundingBox

      public Rectangle2D getBoundingBox()
      Gets the bounding box of the image, that is the size of the rectangle spanning all pixels, that do not have the same color as the background color. This background color is first guessed using the getBackgroundColor() method.
      Returns:
      The calculated bounding box based on the guessed background color.
      See Also:
    • getBoundingBox

      public Rectangle2D getBoundingBox(Color bgcolor)
      Gets the bounding box of the image, that is the size of the rectangle spanning all pixels, that do not have the same color as the given color which is supposed to be the background color.

      The algorithm scans starting on each edge of the image rectangle and aborts the scan as soon as a non-background pixel is encountered.

      Parameters:
      bgcolor - The color value not being considered image color, ie background color.
      Returns:
      The calculated bounding box based on the guessed background color.
      Throws:
      NullPointerException - if bgcolor is null.
    • floodFill

      public void floodFill(Color fillColor, int blur)
      Floods the background with the new fill color. The backrgound color is first guessed using the getBackgroundColor() method.
      Parameters:
      fillColor - The color to replace the background pixels
      blur - The maximal color distance to apply to a pixel to treat it as a background color pixel.
      See Also:
    • floodFill

      public void floodFill(Color fillColor, int blur, Color bgColor)
      Starting from the four edges of the image towards the center, the method replaces background color by the fill color. Pixels are considered background if the have the same color as the background color or if there color has a distance from the backrgound color which is less than the blur value as per the following formula :
      blur invalid input: '<' sqrt( dr^2 + dg^2 + db^2 )
      where dr, dg and db are the difference of the red, blue and green component of the pixel and the background color, resp.

      As a side effect the transparency color is set to the fill color if the transparency was set to the backrgound color just replaced.

      Parameters:
      fillColor - The color teplace for the background color.
      blur - The maximum color distance as defined above.
      bgColor - The background color to be replaced.
      Throws:
      NullPointerException - if either fillColor or bgColor is null.
    • drawImage

      public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
      Draws the image onto the layers image at the indicated position doing the image operation before drawing. Note that the x and y coordinates are relative to the layers image and not relative to the x/y coordinates of the layer itself. That is, the coordinate 0/0 draws at the top left corner of the layer regardless of the value of the layers x/y value.
      Parameters:
      img - The image to draw
      op - The BufferedImageOp to execute on the image before drawing, if null the image is drawn unaltered.
      x - The left position to draw the image to
      y - The top position to draw the image to
    • draw

      public void draw(Graphics g)
      Draws the layer into another graphics element, for example another image or a canvas. The image is drawn at the position specified by the left and top edge of the layer.
      Parameters:
      g - The graphics element to draw into
    • getX

      public int getX()
      Returns the left edge of the layer. This value is relevant, if the layer is to be merged with other layers, to position the layers relative to each other.
      Returns:
      left edge of the layer.
    • setX

      public void setX(int x)
      Sets the left edge of the layer. This value is relevant, if the layer is to be merged with other layers, to position the layers relative to each other.
      Parameters:
      x - left edge of the layer.
    • getY

      public int getY()
      Returns the top edge of the layer. This value is relevant, if the layer is to be merged with other layers, to position the layers relative to each other.
      Returns:
      top edge of the layer.
    • setY

      public void setY(int y)
      Sets the top edge of the layer. This value is relevant, if the layer is to be merged with other layers, to position the layers relative to each other.
      Parameters:
      y - top edge of the layer.
    • getWidth

      public int getWidth()
      Returns the width of the layer.
      Returns:
      the width of the layer.
    • getHeight

      public int getHeight()
      Returns the height of the layer.
      Returns:
      the height of the layer.
    • getBounds

      public Rectangle getBounds()
      Returns the rectangle spanned by the image. This rectangle encompasses the complete image where as getBoundingBox() returns the smallest area of the image not only covered by the background color.
    • getImageIndex

      public int getImageIndex()
      Returns the index of image of this layer within the multi-image file from which this layer has been loaded. This field will only be non-zero if the layer has been created by a call to the Layer(InputStream, int) constructor with a non-zero index.
      Returns:
      The index of the image of this layer in the image source file.
    • getNumImages

      public int getNumImages()
      Returns the number of images in the source from where this layer has been loaded or -1 if the number of images is not known or the lay has not been loaded from an image file.
      Returns:
      The number of images in the source file or -1 if not known.
    • getBackground

      public Paint getBackground()
      Returns the background of the layer.
      Returns:
      the background of the layer.
    • setBackground

      public void setBackground(Paint bground)
      Sets the background of the layer. If the background is a Color the background color (getBackgroundColor()) is also set.
      Parameters:
      bground - The new background.
    • setBackgroundColor

      public void setBackgroundColor(Color bgColor)
      Set the background color to the indicated value. This value is overwritten by setBackground(Paint) and potentially also by getBackgroundColor().

      You may set the background color to null, if you want to recalculate the background color based on the image data the next time you call getBackgroundColor().

      Parameters:
      bgColor - The Color to set for the background or null to force recalculation by the next getBackgroundColor() call.
    • getBackgroundColor

      public Color getBackgroundColor()
      Gets the background color of the image. If the background color has not been set by setBackgroundColor(Color), the background color is taken to be the background (getBackground() if the background is a color, else the color is calculated to be the color most often occuring on the edges of the layer. This may not be 100% correct but gets acceptable results.
      Returns:
      The supposed background color.
    • getTransparency

      public Color getTransparency()
      Returns the Color value of transparent pixels. This is prominently used by the GIF image format, which does not know about alpha values. For GIF images, a color may be specified to identify pixels which should be show transparent.
      Returns:
      the Color value of transparent pixels
    • setTransparency

      public void setTransparency(Color transparency)
      Sets the Color value of pixels to be regarded transparent. This is prominently used by the GIF image format, which does not know about alpha values. For GIF images, a color may be specified to identify pixels which should be show transparent.
      Parameters:
      transparency - The transparency color.
    • setMimeType

      public void setMimeType(String mimeType)
      Sets the MIME type of the image, which is used when writing the image with no explicite MIME type setting.
      Parameters:
      mimeType - The MIME type to set on the layer. If null or empty, the currently set MIME type is not changed.
    • getMimeType

      public String getMimeType()
      Returns the MIME type of the image from which the layer has been loaded. If the layer is not created from an image, the method returns the default MIME type image/gif.
      Returns:
      the MIME type assigned to the layer.
    • getOpacity

      public float getOpacity()
      Gets the opacity of the layer. The opacity value is used when merging layers to define the relative transparency of two layers merged.
      Returns:
      the layer's opacity.
      See Also:
    • setOpacity

      public void setOpacity(float opacity)
      Sets the opacity of the layer. The opacity value is used when merging layers to define the relative transparency of two layers merged.
      Parameters:
      opacity - the layer's opacity. If less than zero, zero is set; if higher than 1.0, 1.0 is set; if not a number (Float.NaN) the opacity is not changed.
      See Also:
    • getLayerComposite

      public Composite getLayerComposite()
      Returns the current Composite of this layer. The default composite set is AlphaComposite.SrcOver.

      This method returns the Composite which is set on this layer and which is used for layer merging. This is different from the Composite returned from the getComposite() method, which returns the Composite used for drawing operations until reset.

      Returns:
      The current Composite.
      See Also:
    • setLayerComposite

      public void setLayerComposite(Composite layerComposite)
      Sets the AlphaComposite used for merging this layer onto other layers.

      This method sets the Composite on this layer which is used for layer merging. This is different from the Composite set through setComposite(java.awt.Composite), which sets the Composite used for drawing operations until reset.

      Parameters:
      layerComposite - The Composite to set on this layer. If null the current Composite is not changed.
      See Also:
    • getImage

      public BufferedImage getImage()
      Returns the image on which this layer is based. This may not be an RGBA image and may even have a custom color space attached.
      Returns:
      The image on which this layer is based.
    • getG2

      public Graphics2D getG2()
      Returns the Graphics2D object used to draw into this layer.
      Returns:
      the Graphics2D object used to draw into this layer.
    • toString

      public String toString()
      Convert the Layer to some string representation for intelligent display.
      Overrides:
      toString in class Object
      Returns:
      the String representation of the Layer.