Record Class TextWatermark
java.lang.Object
java.lang.Record
cloud.opencode.base.image.watermark.TextWatermark
- Record Components:
text- the watermark text (non-empty) | 水印文字(非空)position- the position | 位置fontFamily- the font family / name (informational; resolved by caller) | 字体族 / 名称(仅信息性,由调用方解析)fontSize- the font pixel height | 字体像素高度colorArgb- the text color, packed ARGB | 文字颜色(打包 ARGB)opacity- the opacity (0.0 to 1.0) | 透明度(0.0 到 1.0)margin- the margin from edge | 边缘间距Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: text/position must not be null - 空值安全: text/position 不能为 null
- All Implemented Interfaces:
Watermark
public record TextWatermark(String text, Position position, String fontFamily, int fontSize, int colorArgb, float opacity, int margin)
extends Record
implements Watermark
Text Watermark
文字水印
Immutable record describing a text watermark. Font is identified by family
name and pixel size only — actual rasterization is done by the caller via
cloud.opencode.base.image.codec.font.Font.rasterize(text, pixelHeight),
which returns the Bitmap that must be passed to
apply(Raster, Bitmap). Color is a packed ARGB int.
描述文字水印的不可变 record。字体仅由名称和像素大小标识 —— 实际光栅化由调用方
通过 Font.rasterize(text, pixelHeight) 完成,返回的 Bitmap 传给
apply(Raster, Bitmap)。颜色为打包 ARGB int。
Usage Examples | 使用示例:
// Simple watermark
TextWatermark watermark = TextWatermark.of("Copyright 2024");
// With position and ARGB color
TextWatermark watermark = TextWatermark.builder()
.text("© 2024 Company")
.position(Position.BOTTOM_RIGHT)
.fontFamily("Arial")
.fontSize(24)
.colorArgb(0xFFFFFFFF)
.opacity(0.8f)
.build();
- Since:
- JDK 25, opencode-base-image V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classText Watermark Builder 文字水印构建器 -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault color (white, alpha=180/255) | 默认颜色(白色,alpha=180/255)static final StringDefault font family | 默认字体族static final intDefault font pixel size | 默认字体像素大小static final intDefault margin | 默认边距static final floatDefault opacity | 默认透明度 -
Constructor Summary
ConstructorsConstructorDescriptionTextWatermark(String text, Position position, String fontFamily, int fontSize, int colorArgb, float opacity, int margin) Compact constructor with validation 紧凑构造函数(带验证) -
Method Summary
Modifier and TypeMethodDescriptionapplyTiled(Raster raster, Bitmap textBitmap, int spacingX, int spacingY) static TextWatermark.Builderbuilder()Create a builder 创建构建器static TextWatermark.Builderbuilder(TextWatermark watermark) Create a builder from existing watermark 从现有水印创建构建器intReturns the value of thecolorArgbrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of thefontFamilyrecord component.intfontSize()Returns the value of thefontSizerecord component.final inthashCode()Returns a hash code value for this object.intmargin()Returns the value of themarginrecord component.static TextWatermarkCreate simple text watermark 创建简单文字水印static TextWatermarkCreate text watermark with position 创建带位置的文字水印floatopacity()Returns the value of theopacityrecord component.position()Returns the value of thepositionrecord component.text()Returns the value of thetextrecord component.final StringtoString()Returns a string representation of this record class.withOpacity(float newOpacity) Create copy with different opacity 创建使用不同透明度的副本withPosition(Position newPosition) Create copy with different position 创建使用不同位置的副本Create copy with different text 创建使用不同文字的副本
-
Field Details
-
DEFAULT_FONT_FAMILY
-
DEFAULT_FONT_SIZE
public static final int DEFAULT_FONT_SIZEDefault font pixel size | 默认字体像素大小- See Also:
-
DEFAULT_COLOR_ARGB
public static final int DEFAULT_COLOR_ARGBDefault color (white, alpha=180/255) | 默认颜色(白色,alpha=180/255)- See Also:
-
DEFAULT_OPACITY
public static final float DEFAULT_OPACITYDefault opacity | 默认透明度- See Also:
-
DEFAULT_MARGIN
public static final int DEFAULT_MARGINDefault margin | 默认边距- See Also:
-
-
Constructor Details
-
TextWatermark
-
-
Method Details
-
of
Create simple text watermark 创建简单文字水印- Parameters:
text- the watermark text | 水印文字- Returns:
- the watermark | 水印
-
of
Create text watermark with position 创建带位置的文字水印- Parameters:
text- the watermark text | 水印文字position- the position | 位置- Returns:
- the watermark | 水印
-
builder
-
builder
Create a builder from existing watermark 从现有水印创建构建器- Parameters:
watermark- the existing watermark | 现有水印- Returns:
- the builder | 构建器
-
withText
Create copy with different text 创建使用不同文字的副本- Parameters:
newText- the new text | 新文字- Returns:
- new watermark | 新水印
-
withPosition
Create copy with different position 创建使用不同位置的副本- Parameters:
newPosition- the new position | 新位置- Returns:
- new watermark | 新水印
-
withOpacity
Create copy with different opacity 创建使用不同透明度的副本- Parameters:
newOpacity- the new opacity | 新透明度- Returns:
- new watermark | 新水印
-
apply
Apply this text watermark on aRasterusing a pre-rasterized text alphaBitmap. 使用预先光栅化的 alphaBitmap在Raster上应用此文字水印。The
Bitmapcan be produced viacloud.opencode.base.image.codec.font.Font.rasterize(text, pixelHeight), which replaces the legacy AWTTextLayout+(pure-Java)pipeline.Bitmap可通过Font.rasterize(text, pixelHeight)获得, 替代旧的 AWTTextLayout+(pure-Java)管线。- Parameters:
raster- target raster | 目标 rastertextBitmap- pre-rasterized text alpha bitmap | 预光栅化的文字 alpha 位图- Returns:
- watermarked
RGBA_8raster | 加水印的RGBA_8raster - Throws:
NullPointerException- if any argument is null | 任意参数为 null 时抛出- Since:
- opencode-base-image V1.0.4
-
applyTiled
Tile this text watermark across aRasterusing a pre-rasterized text alphaBitmap. 使用预光栅化的 alphaBitmap在Raster上平铺此文字水印。- Parameters:
raster- target raster | 目标 rastertextBitmap- pre-rasterized text alpha bitmap | 预光栅化的文字 alpha 位图spacingX- horizontal spacing | 水平间距spacingY- vertical spacing | 垂直间距- Returns:
- tiled-watermarked
RGBA_8raster | 平铺水印后的RGBA_8raster - Throws:
NullPointerException- if any argument is null | 任意参数为 null 时抛出- Since:
- opencode-base-image V1.0.4
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
text
-
position
-
fontFamily
Returns the value of thefontFamilyrecord component.- Returns:
- the value of the
fontFamilyrecord component
-
fontSize
-
colorArgb
-
opacity
-
margin
-