|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.gif4j.Watermark
This java class is used to prepare and apply (render with the specified transparency) images as watermarks. Absolute and layout positioning are supported.
The next examples demonstrate how this java class can be used separately
to create and add watermarks to images (BufferedImage(-s))
and the whole gif images (GifImage(-s)).
Please peruse the API, tutorial and external examples for additional features.
BufferedImage using Java
import com.gif4j.TextPainter;
import com.gif4j.Watermark;
import java.awt.*;
import java.awt.image.BufferedImage;
// ...
public BufferedImage addTextWatermarkToImage(BufferedImage image, String watermarkText) {
//create new TextPainter
TextPainter textPainter = new TextPainter(new Font("Verdana", Font.BOLD, 10));
textPainter.setOutlinePaint(Color.WHITE);
//render the specified text outlined
BufferedImage renderedWatermarkText = textPainter.renderString(watermarkText,true);
//create new Watermark
Watermark watermark = new Watermark(renderedWatermarkText, Watermark.LAYOUT_BOTTOM_RIGHT);
//apply watermark to the specified image and return the result
return watermark.apply(image);
}
GifImage using Java
import com.gif4j.TextPainter;
import com.gif4j.Watermark;
import java.awt.*;
import com.gif4j.GifImage;
// ...
public GifImage addTextWatermarkToGifImage(GifImage gifImage, String watermarkText) {
//create new TextPainter
TextPainter textPainter = new TextPainter(new Font("Verdana", Font.BOLD, 10));
textPainter.setOutlinePaint(Color.WHITE);
//render the specified text outlined
BufferedImage renderedWatermarkText = textPainter.renderString(watermarkText, true);
//create new Watermark
Watermark watermark = new Watermark(renderedWatermarkText, Watermark.LAYOUT_BOTTOM_RIGHT);
//apply watermark to the specified gif image and return the result
return watermark.apply(gifImage, true);
}
GifImage,
BufferedImage| Field Summary | |
static int |
LAYOUT_BOTTOM_CENTER
The bottom-center layout constraint. |
static int |
LAYOUT_BOTTOM_LEFT
The bottom-left layout constraint. |
static int |
LAYOUT_BOTTOM_RIGHT
The bottom-right layout constraint. |
static int |
LAYOUT_COVER_CONSECUTIVELY
By providing this layout constraint an image will be covered by the watermark consecutively. |
static int |
LAYOUT_MIDDLE_CENTER
The middle-center layout constraint. |
static int |
LAYOUT_MIDDLE_LEFT
The middle-left layout constraint. |
static int |
LAYOUT_MIDDLE_RIGHT
The middle-right layout constraint. |
static int |
LAYOUT_TOP_CENTER
The top-center layout constraint |
static int |
LAYOUT_TOP_LEFT
The top-left layout constraint. |
static int |
LAYOUT_TOP_RIGHT
The top-right layout constraint. |
| Constructor Summary | |
Watermark(java.awt.image.BufferedImage watermarkImage,
int layoutConstraint)
Constructs Watermark from the specified BufferedImage
with the specified layout position (final position is calculated according to the specified
layout constraint before the applying process to the exact GifFrame starts), and 0.5 transparency (half-TRANSPARENT_COLOR). |
|
Watermark(java.awt.image.BufferedImage watermarkImage,
int layoutConstraint,
float transparency)
Constructs Watermark from the specified BufferedImage
with the specified layout position (final position is calculated according to the specified
layout constraint before the applying process to the exact GifFrame starts), and the specified transparency. |
|
Watermark(java.awt.image.BufferedImage watermarkImage,
java.awt.Point position)
Constructs Watermark from the specified BufferedImage
with the specified absolute position, and 0.5 transparency (half-TRANSPARENT_COLOR). |
|
Watermark(java.awt.image.BufferedImage watermarkImage,
java.awt.Point position,
float transparency)
Constructs Watermark from the specified BufferedImage
with the specified absolute position and transparency parameter. |
|
| Method Summary | |
java.awt.image.BufferedImage |
apply(java.awt.image.BufferedImage image)
Apply the watermark to the specified image. |
GifImage |
apply(GifImage gifImage,
boolean smooth)
Apply the watermark to the specified GifImage.
|
GifImage |
applyFrame(GifImage gifImage,
int frameNumber,
boolean smooth)
Apply the watermark to the specified GifFrame within the specified GifImage.
|
GifImage |
applyFull(GifImage gifImage,
boolean smooth)
Apply the watermark to the specified GifImage in full mode.
|
void |
setLayoutConstraint(int layoutConstraint)
Set the relative position where this instance should paint itself (final position is calculated according to the specified layout constraint before the applying process to the exact GifFrame starts) |
void |
setPosition(java.awt.Point position)
set absolute position where this instance should paint itself |
void |
setTransparency(float transparency)
Set watermark transparency |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int LAYOUT_BOTTOM_CENTER
public static final int LAYOUT_BOTTOM_LEFT
public static final int LAYOUT_BOTTOM_RIGHT
public static final int LAYOUT_COVER_CONSECUTIVELY
public static final int LAYOUT_MIDDLE_CENTER
public static final int LAYOUT_MIDDLE_LEFT
public static final int LAYOUT_MIDDLE_RIGHT
public static final int LAYOUT_TOP_CENTER
public static final int LAYOUT_TOP_LEFT
public static final int LAYOUT_TOP_RIGHT
| Constructor Detail |
public Watermark(java.awt.image.BufferedImage watermarkImage,
int layoutConstraint)
Watermark from the specified BufferedImage
with the specified layout position (final position is calculated according to the specified
layout constraint before the applying process to the exact GifFrame starts), and 0.5 transparency (half-TRANSPARENT_COLOR).
watermarkImage - the specified watermark imagelayoutConstraint - one of the next:
LAYOUT_TOP_LEFT,
LAYOUT_TOP_CENTER,
LAYOUT_TOP_RIGHT,
LAYOUT_MIDDLE_LEFT,
LAYOUT_MIDDLE_CENTER,
LAYOUT_MIDDLE_RIGHT,
LAYOUT_BOTTOM_LEFT,
LAYOUT_BOTTOM_CENTER,
LAYOUT_BOTTOM_RIGHTjava.lang.NullPointerException - watermarkImage is null
java.lang.IllegalArgumentException - unknown layout constraint
public Watermark(java.awt.image.BufferedImage watermarkImage,
int layoutConstraint,
float transparency)
Watermark from the specified BufferedImage
with the specified layout position (final position is calculated according to the specified
layout constraint before the applying process to the exact GifFrame starts), and the specified transparency.
watermarkImage - the specified watermark imagelayoutConstraint - one of the next:
LAYOUT_TOP_LEFT,
LAYOUT_TOP_CENTER,
LAYOUT_TOP_RIGHT,
LAYOUT_MIDDLE_LEFT,
LAYOUT_MIDDLE_CENTER,
LAYOUT_MIDDLE_RIGHT,
LAYOUT_BOTTOM_LEFT,
LAYOUT_BOTTOM_CENTER,
LAYOUT_BOTTOM_RIGHTtransparency - transparency parameter, must be between 0 (absolutely TRANSPARENT_COLOR) and 1 (absolutely opaque).
java.lang.NullPointerException - watermarkImage is null
java.lang.IllegalArgumentException - unknown layout constraint
public Watermark(java.awt.image.BufferedImage watermarkImage,
java.awt.Point position)
Watermark from the specified BufferedImage
with the specified absolute position, and 0.5 transparency (half-TRANSPARENT_COLOR).
watermarkImage - the specified watermark imageposition - absolute position where this watermark should be painted at
java.lang.NullPointerException - watermarkImage is null
public Watermark(java.awt.image.BufferedImage watermarkImage,
java.awt.Point position,
float transparency)
Watermark from the specified BufferedImage
with the specified absolute position and transparency parameter.
watermarkImage - the specified watermark imageposition - absolute position where this watermark should be painted attransparency - the specified transparency, must be between 0 (absolutely TRANSPARENT_COLOR) and 1 (absolutely opaque).
java.lang.NullPointerException - watermarkImage is null| Method Detail |
public java.awt.image.BufferedImage apply(java.awt.image.BufferedImage image)
image - BufferedImage to apply watermark to
BufferedImage instance with rendered watermark
public GifImage apply(GifImage gifImage,
boolean smooth)
GifImage.
The image watermark is rendered with the specified transparency at the specified position.
The watermark image is applied to the whole GifImage.
gifImage - GifImage to apply watermark tosmooth - choose a watermark-rendering algorithm.
If true then the watermark-rendering algorithm that gives higher priority to GifImage smoothness than rendering speed is used.
GifImage instance with rendered watermark
public final GifImage applyFrame(GifImage gifImage,
int frameNumber,
boolean smooth)
GifFrame within the specified GifImage.
The image watermark is rendered with the specified transparency at the specified position.
gifImage - GifImage to apply watermark toframeNumber - number of frame to apply watermark tosmooth - choose a watermark-rendering algorithm.
If true then the watermark-rendering algorithm that gives higher priority to GifImage smoothness than rendering speed is used.
GifImage instance with rendered watermark
public final GifImage applyFull(GifImage gifImage,
boolean smooth)
GifImage in full mode.
The image watermark is rendered with the specified transparency at the specified position.
The watermark image is applied to the whole GifImage.
gifImage - GifImage to apply watermark tosmooth - choose a watermark-rendering algorithm.
If true then the watermark-rendering algorithm that gives higher priority to GifImage smoothness than rendering speed is used.
GifImage instance with rendered watermarkpublic void setLayoutConstraint(int layoutConstraint)
GifFrame starts)
layoutConstraint - one of the next:
LAYOUT_TOP_LEFT,
LAYOUT_TOP_CENTER,
LAYOUT_TOP_RIGHT,
LAYOUT_MIDDLE_LEFT,
LAYOUT_MIDDLE_CENTER,
LAYOUT_MIDDLE_RIGHT,
LAYOUT_BOTTOM_LEFT,
LAYOUT_BOTTOM_CENTER,
LAYOUT_BOTTOM_RIGHTjava.lang.IllegalArgumentException - unknown layout constraintpublic void setPosition(java.awt.Point position)
position - point instance with positive coordinatespublic void setTransparency(float transparency)
transparency - transparency parameter, must be between 0 (absolutely TRANSPARENT_COLOR) and 1 (absolutely opaque).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||