Record Class TextWatermark
java.lang.Object
java.lang.Record
cloud.opencode.base.image.watermark.TextWatermark
- Record Components:
text- the watermark text | 水印文字position- the position | 位置font- the font | 字体color- the text color | 文字颜色opacity- the opacity (0.0 to 1.0) | 透明度margin- the margin from edge | 边缘间距Features | 主要功能:
- Immutable text watermark configuration - 不可变的文字水印配置
- Builder pattern and factory methods - 构建器模式和工厂方法
- Configurable font, color, position, opacity, and margin - 可配置的字体、颜色、位置、透明度和边距
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: No (text must not be null) - 空值安全: 否(文字不能为 null)
- All Implemented Interfaces:
Watermark
public record TextWatermark(String text, Position position, Font font, Color color, float opacity, int margin)
extends Record
implements Watermark
Text Watermark
文字水印
Immutable record for text watermark configuration.
文字水印配置的不可变记录。
Usage Examples | 使用示例:
// Simple watermark
TextWatermark watermark = TextWatermark.of("Copyright 2024");
// With position
TextWatermark watermark = TextWatermark.of("Copyright", Position.BOTTOM_RIGHT);
// With builder
TextWatermark watermark = TextWatermark.builder()
.text("© 2024 Company")
.position(Position.BOTTOM_RIGHT)
.font(new Font("Arial", Font.BOLD, 24))
.color(Color.WHITE)
.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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTextWatermark(String text, Position position, Font font, Color color, float opacity, int margin) Compact constructor with validation 紧凑构造函数(带验证) -
Method Summary
Modifier and TypeMethodDescriptionstatic TextWatermark.Builderbuilder()Create a builder 创建构建器static TextWatermark.Builderbuilder(TextWatermark watermark) Create a builder from existing watermark 从现有水印创建构建器color()Returns the value of thecolorrecord component.final booleanIndicates whether some other object is "equal to" this one.font()Returns the value of thefontrecord 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 创建带位置的文字水印static TextWatermarkCreate text watermark with position and font 创建带位置和字体的文字水印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
Default font | 默认字体 -
DEFAULT_COLOR
Default color | 默认颜色 -
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 | 水印
-
of
Create text watermark with position and font 创建带位置和字体的文字水印- Parameters:
text- the watermark text | 水印文字position- the position | 位置font- the font | 字体- 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 | 新水印
-
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
-
font
-
color
-
opacity
-
margin
-