Record Class ImageWatermark
java.lang.Object
java.lang.Record
cloud.opencode.base.image.watermark.ImageWatermark
- Record Components:
image- the watermark image | 水印图片position- the position | 位置opacity- the opacity (0.0 to 1.0) | 透明度margin- the margin from edge | 边缘间距Features | 主要功能:
- Immutable image watermark configuration - 不可变的图片水印配置
- Builder pattern and factory methods - 构建器模式和工厂方法
- Configurable position, opacity, and margin - 可配置的位置、透明度和边距
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: No (image must not be null) - 空值安全: 否(图片不能为 null)
- All Implemented Interfaces:
Watermark
public record ImageWatermark(BufferedImage image, Position position, float opacity, int margin)
extends Record
implements Watermark
Image Watermark
图片水印
Immutable record for image watermark configuration.
图片水印配置的不可变记录。
Usage Examples | 使用示例:
// Simple watermark
ImageWatermark watermark = ImageWatermark.of(logoImage);
// With position
ImageWatermark watermark = ImageWatermark.of(logoImage, Position.BOTTOM_RIGHT);
// With builder
ImageWatermark watermark = ImageWatermark.builder()
.image(logoImage)
.position(Position.BOTTOM_RIGHT)
.opacity(0.8f)
.margin(20)
.build();
// With all options
ImageWatermark watermark = new ImageWatermark(logoImage, Position.BOTTOM_RIGHT, 0.5f, 20);
- Since:
- JDK 25, opencode-base-image V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classImage Watermark Builder 图片水印构建器 -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault margin | 默认边距static final floatDefault opacity | 默认透明度 -
Constructor Summary
ConstructorsConstructorDescriptionImageWatermark(BufferedImage image, Position position, float opacity, int margin) Compact constructor with validation 紧凑构造函数(带验证) -
Method Summary
Modifier and TypeMethodDescriptionstatic ImageWatermark.Builderbuilder()Create a builder 创建构建器static ImageWatermark.Builderbuilder(ImageWatermark watermark) Create a builder from existing watermark 从现有水印创建构建器final booleanIndicates whether some other object is "equal to" this one.intGet watermark height 获取水印高度intgetWidth()Get watermark width 获取水印宽度final inthashCode()Returns a hash code value for this object.image()Returns the value of theimagerecord component.intmargin()Returns the value of themarginrecord component.static ImageWatermarkof(BufferedImage image) Create simple image watermark 创建简单图片水印static ImageWatermarkof(BufferedImage image, Position position) Create image watermark with position 创建带位置的图片水印static ImageWatermarkof(BufferedImage image, Position position, float opacity) Create image watermark with position and opacity 创建带位置和透明度的图片水印floatopacity()Returns the value of theopacityrecord component.position()Returns the value of thepositionrecord component.final StringtoString()Returns a string representation of this record class.withImage(BufferedImage newImage) Create copy with different image 创建使用不同图片的副本withMargin(int newMargin) Create copy with different margin 创建使用不同边距的副本withOpacity(float newOpacity) Create copy with different opacity 创建使用不同透明度的副本withPosition(Position newPosition) Create copy with different position 创建使用不同位置的副本
-
Field Details
-
DEFAULT_OPACITY
public static final float DEFAULT_OPACITYDefault opacity | 默认透明度- See Also:
-
DEFAULT_MARGIN
public static final int DEFAULT_MARGINDefault margin | 默认边距- See Also:
-
-
Constructor Details
-
ImageWatermark
Compact constructor with validation 紧凑构造函数(带验证)
-
-
Method Details
-
of
Create simple image watermark 创建简单图片水印- Parameters:
image- the watermark image | 水印图片- Returns:
- the watermark | 水印
-
of
Create image watermark with position 创建带位置的图片水印- Parameters:
image- the watermark image | 水印图片position- the position | 位置- Returns:
- the watermark | 水印
-
of
Create image watermark with position and opacity 创建带位置和透明度的图片水印- Parameters:
image- the watermark image | 水印图片position- the position | 位置opacity- the opacity | 透明度- Returns:
- the watermark | 水印
-
getWidth
public int getWidth()Get watermark width 获取水印宽度- Returns:
- the width | 宽度
-
getHeight
public int getHeight()Get watermark height 获取水印高度- Returns:
- the height | 高度
-
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 | 新水印
-
withMargin
Create copy with different margin 创建使用不同边距的副本- Parameters:
newMargin- the new margin | 新边距- Returns:
- new watermark | 新水印
-
withImage
Create copy with different image 创建使用不同图片的副本- Parameters:
newImage- the new image | 新图片- Returns:
- new watermark | 新水印
-
builder
-
builder
Create a builder from existing watermark 从现有水印创建构建器- Parameters:
watermark- the existing watermark | 现有水印- Returns:
- the builder | 构建器
-
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. -
image
-
position
-
opacity
-
margin
-