Package com.day.image
Class StampOp
- java.lang.Object
-
- com.day.image.AbstractBufferedImageOp
-
- com.day.image.StampOp
-
- All Implemented Interfaces:
java.awt.image.BufferedImageOp
public class StampOp extends AbstractBufferedImageOp
TheStampOp
is an image operation, which may scale the source image to the destination image and put a stamp mark ontop of the (scaled) destination image. The location and size as well as the mark it self must be provided to the operation before thefilter
method is called. The operation can be reused to stamp multiple images.Sample use:
// create op with no rendering hints StampOp op = new StampOp(); // set the stamp image op.setStamp(watermarkImage); // set the top,left location, default is (0, 0) op.setStampLocation(20, 20); // set the stamp size, default is (15, 15) op.setStampSize(30, 30); // draw stamp with 50% opacity (default is 100% opacity) op.setStampComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f)); // apply the stamp stampedImage = op.filter(rawImage, null);
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.image.BufferedImage
filter(java.awt.image.BufferedImage src, java.awt.image.BufferedImage dst)
Applies the stamp on the source image.java.awt.image.BufferedImage
getStamp()
Returns the stamp image ornull
if it has not yet been set.java.awt.Composite
getStampComposite()
Returns the current composite used to draw the image.java.awt.geom.Rectangle2D
getStampPosition()
Returns the stamp location and size as a rectangle whose x and y fields define the top,left position and the width and height of the rectangle define the width and height of the stamp.void
setStamp(java.awt.image.BufferedImage stamp)
Sets the stamp image.void
setStampComposite(java.awt.Composite stampComposite)
Sets theComposite
used to draw the stamp on the image.void
setStampLocation(int x, int y)
Sets the top, left location of the stamp.void
setStampSize(int width, int height)
Sets the width and height of the stamp to be drawn.-
Methods inherited from class com.day.image.AbstractBufferedImageOp
createCompatibleDestImage, getBounds2D, getPoint2D, getRenderingHints
-
-
-
-
Constructor Detail
-
StampOp
public StampOp(java.awt.RenderingHints hints)
Creates an instance of this operation with the given rendering hints.- Parameters:
hints
- The rendering hints to apply for the filter operation. This may benull
.
-
StampOp
public StampOp()
Creates an instance of this operation with no rendering hints.
-
-
Method Detail
-
setStamp
public void setStamp(java.awt.image.BufferedImage stamp)
Sets the stamp image. If this isnull
, the operation does nothing else than copying the source image into the destination image.
-
getStamp
public java.awt.image.BufferedImage getStamp()
Returns the stamp image ornull
if it has not yet been set.
-
setStampLocation
public void setStampLocation(int x, int y)
Sets the top, left location of the stamp.
-
setStampSize
public void setStampSize(int width, int height)
Sets the width and height of the stamp to be drawn.
-
getStampPosition
public java.awt.geom.Rectangle2D getStampPosition()
Returns the stamp location and size as a rectangle whose x and y fields define the top,left position and the width and height of the rectangle define the width and height of the stamp.
-
setStampComposite
public void setStampComposite(java.awt.Composite stampComposite)
Sets theComposite
used to draw the stamp on the image. The default value isAlphaComposite.Src
which draws the stamp with full opacity.- Parameters:
stampComposite
- TheComposite
. If this isnull
the current composite is not replaced.
-
getStampComposite
public java.awt.Composite getStampComposite()
Returns the current composite used to draw the image.
-
filter
public java.awt.image.BufferedImage filter(java.awt.image.BufferedImage src, java.awt.image.BufferedImage dst)
Applies the stamp on the source image. If the src image is equal to the destination image, the stamp is drawn on the original image thus modifying the src image. Otherwise the source image is first copied to the destination, optionally resizing if the destination has a different size. If the destination image isnull
a new image with the same size and color setup as the source image is created to draw the source image and stamp.- Specified by:
filter
in interfacejava.awt.image.BufferedImageOp
- Overrides:
filter
in classAbstractBufferedImageOp
- Parameters:
src
- The src image to be operated upon.dst
- The dest image into which to place the modified image. This may benull
in which case a new image with the correct size will be created.- Returns:
- The newly created image (if dest was
null
) or dest into which the resized src image has been drawn.
-
-