Record Class PdfColor
java.lang.Object
java.lang.Record
cloud.opencode.base.pdf.content.PdfColor
- Record Components:
red- red component (0-1) | 红色分量green- green component (0-1) | 绿色分量blue- blue component (0-1) | 蓝色分量alpha- alpha (0-1, 0=transparent, 1=opaque) | 透明度model- color model | 颜色模型
public record PdfColor(float red, float green, float blue, float alpha, PdfColor.ColorModel model)
extends Record
PDF Color - Color representation for PDF content
PDF 颜色 - PDF 内容的颜色表示
Supports RGB, CMYK, and grayscale color models.
支持 RGB、CMYK 和灰度颜色模型。
Features | 主要功能:
- RGB, RGBA, and grayscale color creation - RGB、RGBA 和灰度颜色创建
- Hex string parsing - 十六进制字符串解析
- Color manipulation (darker, lighter, alpha) - 颜色操作(加深、变浅、透明度)
- AWT Color interoperability - AWT Color 互操作
- Predefined color constants - 预定义颜色常量
Usage Examples | 使用示例:
PdfColor red = PdfColor.rgb(255, 0, 0);
PdfColor custom = PdfColor.hex("#3366CC");
PdfColor semiTransparent = PdfColor.rgba(0, 0, 0, 0.5f);
PdfColor darkRed = PdfColor.RED.darker(0.7f);
Security | 安全性:
- Thread-safe: Yes — immutable record - 线程安全: 是 — 不可变记录
- Null-safe: No — factory methods do not validate null inputs - 空值安全: 否 — 工厂方法不验证空输入
- Since:
- JDK 25, opencode-base-pdf V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PdfColorBlack color | 黑色static final PdfColorBlue color | 蓝色static final PdfColorCyan color | 青色static final PdfColorDark gray color | 深灰色static final PdfColorGray color | 灰色static final PdfColorGreen color | 绿色static final PdfColorLight gray color | 浅灰色static final PdfColorMagenta color | 品红色static final PdfColorOrange color | 橙色static final PdfColorRed color | 红色static final PdfColorWhite color | 白色static final PdfColorYellow color | 黄色 -
Constructor Summary
ConstructorsConstructorDescriptionPdfColor(float red, float green, float blue, float alpha, PdfColor.ColorModel model) Creates an instance of aPdfColorrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfloatalpha()Returns the value of thealpharecord component.floatblue()Returns the value of thebluerecord component.darker(float factor) Creates a darker version of this color 创建当前颜色的深色版本final booleanIndicates whether some other object is "equal to" this one.static PdfColorCreates color from java.awt.Color 从 java.awt.Color 创建颜色floatgetAlpha()Gets alpha (opacity) 获取透明度floatgetBlue()Gets blue component (0-1) 获取蓝色分量 (0-1)floatgetGreen()Gets green component (0-1) 获取绿色分量 (0-1)getModel()Gets color model 获取颜色模型floatgetRed()Gets red component (0-1) 获取红色分量 (0-1)static PdfColorgray(float gray) Creates grayscale color from 0-1 value 从 0-1 值创建灰度颜色static PdfColorgray(int gray) Creates grayscale color 创建灰度颜色floatgreen()Returns the value of thegreenrecord component.final inthashCode()Returns a hash code value for this object.static PdfColorCreates color from hex string 从十六进制字符串创建颜色lighter(float factor) Creates a lighter version of this color 创建当前颜色的浅色版本model()Returns the value of themodelrecord component.floatred()Returns the value of theredrecord component.static PdfColorrgb(float r, float g, float b) Creates RGB color from 0-1 values 从 0-1 值创建 RGB 颜色static PdfColorrgb(int r, int g, int b) Creates RGB color from 0-255 values 从 0-255 值创建 RGB 颜色static PdfColorrgba(int r, int g, int b, float alpha) Creates RGBA color with alpha 创建带透明度的 RGBA 颜色Converts to java.awt.Color 转换为 java.awt.ColortoHex()Converts to hex string 转换为十六进制字符串toString()Returns a string representation of this record class.withAlpha(float newAlpha) Creates a color with different alpha 创建具有不同透明度的颜色
-
Field Details
-
BLACK
Black color | 黑色 -
WHITE
White color | 白色 -
RED
Red color | 红色 -
GREEN
Green color | 绿色 -
BLUE
Blue color | 蓝色 -
GRAY
Gray color | 灰色 -
LIGHT_GRAY
Light gray color | 浅灰色 -
DARK_GRAY
Dark gray color | 深灰色 -
YELLOW
Yellow color | 黄色 -
CYAN
Cyan color | 青色 -
MAGENTA
Magenta color | 品红色 -
ORANGE
Orange color | 橙色
-
-
Constructor Details
-
PdfColor
Creates an instance of aPdfColorrecord class.
-
-
Method Details
-
rgb
Creates RGB color from 0-255 values 从 0-255 值创建 RGB 颜色- Parameters:
r- red component (0-255) | 红色分量g- green component (0-255) | 绿色分量b- blue component (0-255) | 蓝色分量- Returns:
- PdfColor instance | PdfColor 实例
-
rgb
Creates RGB color from 0-1 values 从 0-1 值创建 RGB 颜色- Parameters:
r- red component (0-1) | 红色分量g- green component (0-1) | 绿色分量b- blue component (0-1) | 蓝色分量- Returns:
- PdfColor instance | PdfColor 实例
-
rgba
Creates RGBA color with alpha 创建带透明度的 RGBA 颜色- Parameters:
r- red component (0-255) | 红色分量g- green component (0-255) | 绿色分量b- blue component (0-255) | 蓝色分量alpha- alpha (0-1, 0=transparent, 1=opaque) | 透明度- Returns:
- PdfColor instance | PdfColor 实例
-
gray
Creates grayscale color 创建灰度颜色- Parameters:
gray- gray level (0-255) | 灰度级别- Returns:
- PdfColor instance | PdfColor 实例
-
gray
Creates grayscale color from 0-1 value 从 0-1 值创建灰度颜色- Parameters:
gray- gray level (0-1) | 灰度级别- Returns:
- PdfColor instance | PdfColor 实例
-
hex
-
from
-
getRed
public float getRed()Gets red component (0-1) 获取红色分量 (0-1)- Returns:
- red component | 红色分量
-
getGreen
public float getGreen()Gets green component (0-1) 获取绿色分量 (0-1)- Returns:
- green component | 绿色分量
-
getBlue
public float getBlue()Gets blue component (0-1) 获取蓝色分量 (0-1)- Returns:
- blue component | 蓝色分量
-
getAlpha
public float getAlpha()Gets alpha (opacity) 获取透明度- Returns:
- alpha (0-1) | 透明度
-
getModel
-
toAwtColor
-
toHex
Converts to hex string 转换为十六进制字符串- Returns:
- hex string (e.g., "#FF0000") | 十六进制字符串
-
darker
Creates a darker version of this color 创建当前颜色的深色版本- Parameters:
factor- darkening factor (0-1) | 加深因子- Returns:
- darker color | 深色颜色
-
lighter
Creates a lighter version of this color 创建当前颜色的浅色版本- Parameters:
factor- lightening factor (0-1) | 变浅因子- Returns:
- lighter color | 浅色颜色
-
withAlpha
Creates a color with different alpha 创建具有不同透明度的颜色- Parameters:
newAlpha- new alpha value | 新的透明度值- Returns:
- color with new alpha | 具有新透明度的颜色
-
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. -
red
-
green
-
blue
-
alpha
-
model
-