Class Layer
- java.lang.Object
-
- com.day.image.Layer
-
public class Layer extends java.lang.Object
TheLayer
class provides a simplified usage pattern for doing graphics rendering. As such theLayer
class forms the basis of Graphics Engine. The implementation is closely based on theBufferedImage
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
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 theLayer
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 asgetPixel(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 aColor
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
objectsx, 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 class
Layer.LuminanceSystem
TheLuminanceSystem
class encapsulates luminance factor values for greyscaling operations.
-
Field Summary
Fields Modifier and Type Field Description static int
ALPHA_CHANNEL_ID
Channel number to identify the alpha channel for diverse methods involving color channels, i.e.static int
BLUE_CHANNEL_ID
Channel number to identify the blue color channel for diverse methods involving color channels, i.e.static java.lang.String
DEFAULT_MIME_TYPE
Default MIME type for writing the image.static Layer.LuminanceSystem
GAMMA22
Luminance factors for RGB in a Gamma 2.2 color space.static int
GREEN_CHANNEL_ID
Channel number to identify the green color channel for diverse methods involving color channels, i.e.static Layer.LuminanceSystem
LINEAR
Luminance factors for RGB in a linear color space.static Layer.LuminanceSystem
REC709
Luminance factors for RGB in a color space for contemporary CRT phosphors according to Rec.static int
RED_CHANNEL_ID
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, java.awt.Paint bground)
Creates aLayer
with the indicated dimensions and background paint.Layer(Layer src)
Creates a newLayer
by copying the image of the source layer and setting all properties to the exact same value they are set in the source layer.Layer(java.awt.image.BufferedImage image)
Creates a newLayer
by wrapping theBufferedImage
with theLayer
properties.Layer(java.io.InputStream input)
Creates a newLayer
instance by loading an image from theInputStream
.Layer(java.io.InputStream input, int idx)
Creates a newLayer
instance by loading the indexed image from theInputStream
.Layer(java.io.InputStream input, int idx, java.awt.Dimension max)
Creates a newLayer
instance by loading the indexed image from theInputStream
.Layer(java.io.InputStream input, int idx, java.awt.Dimension max, javax.imageio.ImageReadParam params)
Creates a newLayer
instance by loading the indexed image from theInputStream
.Layer(java.io.InputStream input, java.awt.Dimension max)
Creates a newLayer
instance by loading an image from theInputStream
.
-
Method Summary
All Methods Instance Methods Concrete Methods 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(java.awt.Color darkcolor, java.awt.Color brightcolor)
Colorizes the layer, i.e.void
colorMask(Layer src, java.awt.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
crop(java.awt.geom.Rectangle2D rect)
Get the subimage indicated by the rectangle from the layer.void
dispose()
Releases as much resources as possible.void
draw(java.awt.Graphics g)
Draws the layer into another graphics element, for example another image or a canvas.void
draw(java.awt.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(java.awt.image.BufferedImage img, java.awt.image.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 thepoints
array.void
drawRect(java.awt.geom.Rectangle2D rect)
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, java.lang.String text, AbstractFont font, int align, double cs, int ls)
Render the given text string in the given font to theLayer
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(java.awt.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
fillRect(Layer src, java.awt.geom.Rectangle2D rect)
Fill the given rectangle with the layer defined as the temporary paint object.void
fillRect(java.awt.geom.Rectangle2D rect)
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(java.awt.Color color)
Adapt the alpha channel of the image so that each color value has its value multiplied with the alpha value.void
flipHorizontally()
Flips the layer horizontally.void
flipVertically()
Flips the layer vertically.void
floodFill(java.awt.Color fillColor, int blur)
Floods the background with the new fill color.void
floodFill(java.awt.Color fillColor, int blur, java.awt.Color bgColor)
Starting from the four edges of the image towards the center, the method replaces background color by the fill color.java.awt.Paint
getBackground()
Returns the background of the layer.java.awt.Color
getBackgroundColor()
Gets the background color of the image.java.awt.geom.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.java.awt.geom.Rectangle2D
getBoundingBox(java.awt.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.java.awt.Rectangle
getBounds()
Returns the rectangle spanned by the image.java.awt.Composite
getComposite()
Returns the current Composite in the Graphics2D context.java.awt.Graphics2D
getG2()
Returns theGraphics2D
object used to draw into this layer.int
getHeight()
Returns the height of the layer.java.awt.image.BufferedImage
getImage()
Returns the image on which this layer is based.int
getImageIndex()
Returns the index of image of this layer within the multi-image file from which this layer has been loaded.java.awt.Composite
getLayerComposite()
Returns the currentComposite
of this layer.java.lang.String
getMimeType()
Returns the MIME type of the image from which the layer has been loaded.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.float
getOpacity()
Gets the opacity of the layer.java.awt.Paint
getPaint()
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 valuejava.lang.Object
getRenderingHint(java.awt.RenderingHints.Key hintKey)
Returns the value of a single preference for the rendering algorithms.java.awt.Stroke
getStroke()
java.awt.Color
getTransparency()
Returns theColor
value of transparent pixels.int
getWidth()
Returns the width of the layer.int
getX()
Returns the left edge of the layer.int
getY()
Returns the top edge of the layer.void
grayscale()
Converts the color image into a grayscale imagevoid
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(java.awt.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(java.awt.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
setBackground(java.awt.Paint bground)
Sets the background of the layer.void
setBackgroundColor(java.awt.Color bgColor)
Set the background color to the indicated value.void
setComposite(java.awt.Composite composite)
Sets the drawing composite for drawing and filling operations to the composite given.void
setLayerComposite(java.awt.Composite layerComposite)
Sets theAlphaComposite
used for merging this layer onto other layers.void
setLineStyle(LineStyle lineStyle)
Sets both the paint and the stroke for the next draw and fill operations.void
setLuminanceSystem(Layer.LuminanceSystem system)
Define the set of color weights to use in luminance definitionvoid
setMimeType(java.lang.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(java.awt.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
setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)
Sets the value of a single preference for the rendering algorithms.void
setStroke(java.awt.Stroke stroke)
Sets the line stroke to use for the subsequent draw operation.void
setTransform(java.awt.geom.AffineTransform transfrom)
Sets the affine transformation applied to all of the drawing and filling operations.void
setTransparency(java.awt.Color transparency)
Sets theColor
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.java.lang.String
toString()
Convert the Layer to some string representation for intelligent display.boolean
write(java.lang.String mimeType, double quality, java.io.OutputStream outStream)
Write the image to the givenOutputStream
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.
-
-
-
Field Detail
-
GAMMA22
public static final Layer.LuminanceSystem GAMMA22
Luminance factors for RGB in a Gamma 2.2 color space. Used for grayscaling. These values constitute the luminance vector with NTSC weights which are also used in the Communiqu� 2 Layer host object.
-
LINEAR
public static final Layer.LuminanceSystem LINEAR
Luminance factors for RGB in a linear color space. Used for grayscaling.
-
REC709
public static final Layer.LuminanceSystem REC709
Luminance factors for RGB in a color space for contemporary CRT phosphors according to Rec. 709 ( ITU-R Recommendation BT.709, Basic Parameter Values for the HDTV Standard for the Studio and for International Programme Exchange (1990)). Used for grayscaling.
-
DEFAULT_MIME_TYPE
public static final java.lang.String DEFAULT_MIME_TYPE
Default MIME type for writing the image. This value is only used, if it could not be deduced from the image (e.g. when loading a picture) or as parameter to thewrite
methods.- See Also:
- Constant Field Values
-
RED_CHANNEL_ID
public static final int RED_CHANNEL_ID
Channel number to identify the red color channel for diverse methods involving color channels, i.e.copyChannel(Layer, int, int)
- See Also:
- Constant Field Values
-
GREEN_CHANNEL_ID
public static final int GREEN_CHANNEL_ID
Channel number to identify the green color channel for diverse methods involving color channels, i.e.copyChannel(Layer, int, int)
- See Also:
- Constant Field Values
-
BLUE_CHANNEL_ID
public static final int BLUE_CHANNEL_ID
Channel number to identify the blue color channel for diverse methods involving color channels, i.e.copyChannel(Layer, int, int)
- See Also:
- Constant Field Values
-
ALPHA_CHANNEL_ID
public static final int ALPHA_CHANNEL_ID
Channel number to identify the alpha channel for diverse methods involving color channels, i.e.copyChannel(Layer, int, int)
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Layer
public Layer(int width, int height, java.awt.Paint bground)
Creates aLayer
with the indicated dimensions and background paint. The background paint may be any validPaint
implementation but will usually be a simpleColor
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 backgroundPaint
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 benull
in which case the background is assumed to be in transparent white.- Throws:
java.lang.IllegalArgumentException
- if either the width or the height are specified lower than 1.
-
Layer
public Layer(java.io.InputStream input) throws java.io.IOException, javax.imageio.IIOException
Creates a newLayer
instance by loading an image from theInputStream
.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:
java.lang.NullPointerException
- if theInputStream
isnull
.java.io.IOException
- if reading from the stream throws such an exception.javax.imageio.IIOException
- if decoding the image fails
-
Layer
public Layer(java.io.InputStream input, java.awt.Dimension max) throws java.io.IOException, javax.imageio.IIOException
Creates a newLayer
instance by loading an image from theInputStream
.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 theLayer(InputStream, int, Dimension)
constructor with an index value or zero.- Parameters:
input
- The InputStream to read the image data frommax
- optional constraint for the maximal dimensions.- Throws:
java.lang.NullPointerException
- if theInputStream
isnull
.java.io.IOException
- if reading from the stream throws such an exception.javax.imageio.IIOException
- if decoding the image fails
-
Layer
public Layer(java.io.InputStream input, int idx) throws java.io.IOException, javax.imageio.IIOException
Creates a newLayer
instance by loading the indexed image from theInputStream
.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 fromidx
- 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:
java.lang.NullPointerException
- if theInputStream
isnull
.java.lang.IndexOutOfBoundsException
- Ifidx
is higher than the index of the last image in the image file.java.io.IOException
- if reading from the stream throws such an exception.javax.imageio.IIOException
- if decoding the image fails
-
Layer
public Layer(java.io.InputStream input, int idx, java.awt.Dimension max) throws java.io.IOException, javax.imageio.IIOException
Creates a newLayer
instance by loading the indexed image from theInputStream
.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 fromidx
- 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:
java.lang.NullPointerException
- if theInputStream
isnull
.java.lang.IndexOutOfBoundsException
- Ifidx
is higher than the index of the last image in the image file.java.io.IOException
- if reading from the stream throws such an exception.javax.imageio.IIOException
- if decoding the image fails
-
Layer
public Layer(java.io.InputStream input, int idx, java.awt.Dimension max, javax.imageio.ImageReadParam params) throws java.io.IOException, javax.imageio.IIOException
Creates a newLayer
instance by loading the indexed image from theInputStream
.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 fromidx
- 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 ofImageReadParam
.- Throws:
java.lang.NullPointerException
- if theInputStream
isnull
.java.lang.IndexOutOfBoundsException
- Ifidx
is higher than the index of the last image in the image file.java.io.IOException
- if reading from the stream throws such an exception.javax.imageio.IIOException
- if decoding the image fails
-
Layer
public Layer(Layer src)
Creates a newLayer
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:
java.lang.NullPointerException
- if the source layer isnull
.
-
Layer
public Layer(java.awt.image.BufferedImage image)
Creates a newLayer
by wrapping theBufferedImage
with theLayer
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
- TheBufferedImage
to wrap as aLayer
.- Throws:
java.lang.NullPointerException
- if the image isnull
.
-
-
Method Detail
-
write
public boolean write(java.lang.String mimeType, double quality, java.io.OutputStream outStream) throws javax.imageio.IIOException, java.io.IOException
Write the image to the givenOutputStream
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 perDEFAULT_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:
java.lang.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.java.lang.NullPointerException
- if theOutputStream
isnull
.javax.imageio.IIOException
- we get from the ImageIO Library we use.java.io.IOException
- we get from writing to theOutputStream
.
-
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
NullPointerException
s.
-
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
- theLayer
s to merge onto this one. Ifnull
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
andcomposite
set on the layer to be painted. If thegetLayerComposite()
is not aAlphaComposite
, theopacity
is ignored.This method is conservative in that it is a null operation if the layers is
null
or empty.- Parameters:
layers
- the list ofLayer
s 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 theLayer
.- Parameters:
src
- the sourceLayer
to copy fromdw
- the width of reactangle to copydh
- the height of the rectangle to copy.- See Also:
blit(Layer, int, int, int, int, int, int)
-
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 sourceLayer
to copy fromdx
- the left edge of the destination area in this layerdy
- the top edge of the destination area in this layerdw
- the width of reactangle to copydh
- the height of the rectangle to copy.sx
- the left edge of the source area in the source layersy
- 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 isl.copyChannel(null, c, c)
will do nothing.- Parameters:
src
- the source layer for the channel copy, ifnull
this is used as thesrc
.fromChannel
- channel to copy from the the source layer. If negative, the alpha channel will be copiedtoChannel
- channel in this layer to copy the fromChannel into. If negative the same channel as fromChannel will be used.- Throws:
java.lang.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, java.awt.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 ornull
this.col
- the color to set for identical pixels. Ifnull
opaque black is used.
-
flatten
public void flatten(java.awt.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 totrue
a faster resizing algorithm is used but with poorer detail.
-
crop
public void crop(java.awt.geom.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 thecrop
parameter, the size of the layer is adapted to the new size or not. Ifcrop==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 theDistortOp
class.- Parameters:
x1
- x-coordinate of top left corner of transformed rectangley1
- y-coordinate of top left corner of transformed rectanglex2
- x-coordinate of top right corner of transformed rectangley2
- y-coordinate of top right corner of transformed rectanglex3
- x-coordinate of bottom left corner of transformed rectangley3
- y-coordinate of bottom left corner of transformed rectanglex4
- x-coordinate of bottom right corner of transformed rectangley4
- y-coordinate of bottom right corner of transformed rectanglecrop
-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(java.awt.Color darkcolor, java.awt.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(java.awt.Color color)
Monotonize the image with a base color other than black. This method is equivalent to callingmultitone(new Color[]{ color })
.- Parameters:
color
- Color to use as the base for the monotonized image- Throws:
java.lang.NullPointerException
- if the color value isnull
.
-
multitone
public void multitone(java.awt.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:
java.lang.NullPointerException
- if the colors array or any of the elements in the array isnull
.java.lang.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 theMultitoneOp
filter.- See Also:
MultitoneOp
,ColorCurve
-
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 theConvolveOp
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 momentgran
- (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.0radius
- Size of the convolution matrix. The size is rounded to and integral matrix edge according toedge = 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 pixelvector
- 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 modifiedcolor2
- New color of those pixelsignoreAlpha
- 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.
destination = ( source * contrast ) + brightness
The result is clipped to the range 0..255.- Parameters:
brightness
- The brightness operand in the range -255 .. 255contrast
- 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(java.awt.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 anyPaint
implementations such asGradientPaint
.The paint setting remains active until changed by the next setLineStyle() or setPaint() call.
-
getPaint
public java.awt.Paint getPaint()
-
setStroke
public void setStroke(java.awt.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 java.awt.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(java.awt.Composite composite)
Sets the drawing composite for drawing and filling operations to the composite given. Most commonly the composite will be one of the predefinedAlphaComposite
implementations.- Parameters:
composite
- The composite to set for the drawing operations.- Throws:
java.lang.NullPointerException
- if composite isnull
.
-
getComposite
public java.awt.Composite getComposite()
Returns the current Composite in the Graphics2D context.- Returns:
- the current Graphics2D Composite, which defines a compositing style.
-
setTransform
public void setTransform(java.awt.geom.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
-
setRenderingHint
public void setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.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 java.lang.Object getRenderingHint(java.awt.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, java.lang.String text, AbstractFont font, int align, double cs, int ls)
Render the given text string in the given font to theLayer
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 attributesheight
- maximum height of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributestext
- the text string to drawfont
- the font to render the text stringalign
- alignment, rotation and TrueType attributes for the text. UseAbstractFont.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:
java.lang.NullPointerException
- if either the text or the font argument isnull
.java.lang.IllegalArgumentException
- if either x or y are negative.- See Also:
Font.drawText(com.day.image.Layer, int, int, int, int, java.lang.String, java.awt.Paint, java.awt.Stroke, int, double, int)
-
fillRect
public void fillRect(java.awt.geom.Rectangle2D rect)
According to the current paint and composite setting, the given rectangle is drawn onto the layer. If the rect parameter isnull
, 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, java.awt.geom.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 sourceLayer
to use. If this is the same assrc
, nothin happens.rect
- the rectangle to paint onto the layer. If set to null, the entire layer will be filled with that color.- Throws:
java.lang.NullPointerException
- ifsrc
isnull
.
-
drawRect
public void drawRect(java.awt.geom.Rectangle2D rect)
Draws the outline of the given rectangle with the preset color and stroke obeying the current composite setting. If rect isnull
, 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 pointy1
- The y coordinate of the starting pointx2
- The x coordinate of the ending pointy2
- The y coordinate of the ending point
-
drawPolyLine
public void drawPolyLine(float[][] points)
Draws a connected lines of multiple points given in thepoints
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 centercy
- The y coordinate of the ellipse centera
- The horizontal radius of the ellipseb
- 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 centercy
- The y coordinate of the ellipse centera
- The horizontal radius of the ellipseb
- 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 fordrawEllipse(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 centercy
- The y coordinate of the base ellipse centera
- The horizontal radius of the base ellipseb
- The vertical radius of the base ellipsefrom
- The starting angle as defined aboveextent
- 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 centercy
- The y coordinate of the base ellipse centera
- The horizontal radius of the base ellipseb
- The vertical radius of the base ellipsefrom
- The starting angle as defined aboveextent
- 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 fordrawEllipse(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 centercy
- The y coordinate of the base ellipse centera
- The horizontal radius of the base ellipseb
- The vertical radius of the base ellipsefrom
- The starting angle as defined aboveextent
- The angle the arc spans as defined above
-
draw
public void draw(java.awt.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 aShape
.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
- TheShape
implementation object to draw
-
fill
public void fill(java.awt.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 aShape
.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
- TheShape
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 pixely
- 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 pixely
- vertical coordinate (0 at the top) of the pixelcolor
- ARGB value for the pixel
-
getBoundingBox
public java.awt.geom.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 thegetBackgroundColor()
method.- Returns:
- The calculated bounding box based on the guessed background color.
- See Also:
getBoundingBox(Color)
-
getBoundingBox
public java.awt.geom.Rectangle2D getBoundingBox(java.awt.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:
java.lang.NullPointerException
- if bgcolor isnull
.
-
floodFill
public void floodFill(java.awt.Color fillColor, int blur)
Floods the background with the new fill color. The backrgound color is first guessed using thegetBackgroundColor()
method.- Parameters:
fillColor
- The color to replace the background pixelsblur
- The maximal color distance to apply to a pixel to treat it as a background color pixel.- See Also:
floodFill(Color, int, Color)
-
floodFill
public void floodFill(java.awt.Color fillColor, int blur, java.awt.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 < sqrt( dr^2 + dg^2 + db^2 )
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:
java.lang.NullPointerException
- if either fillColor or bgColor isnull
.
-
drawImage
public void drawImage(java.awt.image.BufferedImage img, java.awt.image.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 drawop
- TheBufferedImageOp
to execute on the image before drawing, ifnull
the image is drawn unaltered.x
- The left position to draw the image toy
- The top position to draw the image to
-
draw
public void draw(java.awt.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 java.awt.Rectangle getBounds()
Returns the rectangle spanned by the image. This rectangle encompasses the complete image where asgetBoundingBox()
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 theLayer(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 java.awt.Paint getBackground()
Returns the background of the layer.- Returns:
- the background of the layer.
-
setBackground
public void setBackground(java.awt.Paint bground)
Sets the background of the layer. If the background is aColor
the background color (getBackgroundColor()
) is also set.- Parameters:
bground
- The new background.
-
setBackgroundColor
public void setBackgroundColor(java.awt.Color bgColor)
Set the background color to the indicated value. This value is overwritten bysetBackground(Paint)
and potentially also bygetBackgroundColor()
.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 callgetBackgroundColor()
.- Parameters:
bgColor
- TheColor
to set for the background ornull
to force recalculation by the nextgetBackgroundColor()
call.
-
getBackgroundColor
public java.awt.Color getBackgroundColor()
Gets the background color of the image. If the background color has not been set bysetBackgroundColor(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 java.awt.Color getTransparency()
Returns theColor
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(java.awt.Color transparency)
Sets theColor
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(java.lang.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. Ifnull
or empty, the currently set MIME type is not changed.
-
getMimeType
public java.lang.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 typeimage/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(float)
-
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:
getOpacity()
-
getLayerComposite
public java.awt.Composite getLayerComposite()
Returns the currentComposite
of this layer. The default composite set isAlphaComposite.SrcOver
.This method returns the
Composite
which is set on this layer and which is used for layer merging. This is different from theComposite
returned from thegetComposite()
method, which returns theComposite
used for drawing operations until reset.- Returns:
- The current
Composite
. - See Also:
setLayerComposite(java.awt.Composite)
-
setLayerComposite
public void setLayerComposite(java.awt.Composite layerComposite)
Sets theAlphaComposite
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 theComposite
set throughsetComposite(java.awt.Composite)
, which sets theComposite
used for drawing operations until reset.- Parameters:
layerComposite
- TheComposite
to set on this layer. Ifnull
the currentComposite
is not changed.- See Also:
getLayerComposite()
-
getImage
public java.awt.image.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 java.awt.Graphics2D getG2()
Returns theGraphics2D
object used to draw into this layer.- Returns:
- the
Graphics2D
object used to draw into this layer.
-
toString
public java.lang.String toString()
Convert the Layer to some string representation for intelligent display.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the
String
representation of theLayer
.
-
-