public final class AlphaComposite extends Object implements Composite
AlphaComposite
类实现基本的alpha合成相结合的源和目标的颜色来实现融合,图形和图像的透明度的影响规律。具体规则实施的这类规则在12 T.波特和T. Duff描述的基本设置,“合成图像”,SIGGRAPH 84,253-259。本文档的其余部分假定一些熟悉该文件中概述的定义和概念。
这类扩展的Porter和达夫的定义包括一个额外的因素的标准方程。AlphaComposite
类的实例可以包含一个α值,以前是用在混合方程修改每个源像素的不透明度或覆盖。
需要注意的是,通过波特和达夫文定义的方程都是定义在预乘相应的alpha分量颜色组件运行的重要。由于ColorModel
和Raster
类允许在进行或不进行像素数据的存储形式,所有输入的数据必须进行归一化到形式在应用方程和结果可能需要调整到所需的目的地之前的像素值存储的形式。
还请注意,这个类只定义了一个纯粹的数学意义上的颜色和阿尔法值相结合的方程。它的方程的精确应用取决于数据检索的方式,从它的来源和存储在它的目的地。更多信息参阅Implementation Caveats。
以下因素是用于描述的混合方程在波特和Duff了:
Factor Definition As the alpha component of the source pixel Cs a color component of the source pixel in premultiplied form Ad the alpha component of the destination pixel Cd a color component of the destination pixel in premultiplied form Fs the fraction of the source pixel that contributes to the output Fd the fraction of the destination pixel that contributes to the output Ar the alpha component of the result Cr a color component of the result in premultiplied form
利用这些因素,波特和Duff定义的混合因素选择FS和FD产生12个理想的视觉效果的12种方法。确定FS和Fd方程是在12的静态字段指定的视觉效果的描述。例如,对于SRC_OVER
描述指定FS = 1和FD =(1-as)。一旦确定混合因子的一组方程是已知的,它们可以被施加到每个像素,以产生一个结果,使用以下的方程组:
的= F(广告)FD = F(AS)AR = * FS +广告* FDCR = CS FS + CD FD
以下因素将被用来讨论我们的扩展混合方程在波特和Duff了:
Factor Definition Csr one of the raw color components of the source pixel Cdr one of the raw color components of the destination pixel Aac the "extra" alpha component from the AlphaComposite instance Asr the raw alpha component of the source pixel Adr the raw alpha component of the destination pixel Adf the final alpha component stored in the destination Cdf the final raw color component stored in the destination
的AlphaComposite
类定义了一个额外的alpha值,应用于源α。这个值作为一个隐含的规则,如果src_in都原源α和原始的颜色乘以在AlphaComposite
α源像素与像素的显示α的首次应用。这将导致如下方程用于生产用于波特和Duff混合方程α:
= ASR * AAC所有原始颜色分量需要乘以在
AlphaComposite
实例的α。此外,如果源不在形式,然后进行颜色分量还需要乘以源α。因此,生产的波特和Duff方程的源颜色分量方程取决于源的像素进行或不
CS =责任* ASR * AAC(如果源不规则)CS =责任* AAC(如果源进行)没有调整需要到目的地
广告= ADRα:
目标颜色组件只需要如果他们不进行调整:
CD = CDR *广告(如果目标不规则)CD = CDR(如果目标进行)
调整后,AD,CS,和CD中使用的标准波特和Duff方程来计算混合因素FS和FD然后进行成分导致AR和Cr.
结果只需要如果他们被存储到一个目的地的缓冲区,认为不进行数据调整,使用下面的公式:
ADF = ARCDF = Cr(如果dest进行)CDF =铬/ AR(如果dest不规则)注意因为如果得到的α为零的划分不明确,在这种情况下,司略为避免“零”和颜色分量为零分离开
出于性能原因,最好是Raster
对象传递到一个由AlphaComposite
类创建对象的方法有CompositeContext
compose
进行数据。如果源或目的地Raster
Raster
不进行适当的转换,但是,之前和之后进行合成操作。
BufferedImage
类上市不透明的图像类型,不存储的像素的alpha值。这样的来源为所有的像素提供了1的α。BufferedImage.TYPE_BYTE_INDEXED
不应作为一个混合操作的目的是因为每一个操作,可以引入较大的误差,由于需要选择从一个有限的调色板像素匹配的混合方程的结果。通常的整数的值是在这样一种方式,整数0等同于浮点值0和整数2 ^ n-1的浮点值相关(其中n是表示的比特数)等于1。8位表示,这意味着0x00代表0和0xFF表示1。
(A,R,G,B)=(0x01,0xb0,0x00,0x00)
如果整数数学被使用,这个值被组合在SRC
模式没有额外的α,然后数学表示结果(整数格式):
(A,R,G,B)=(0x01,0x01,0x00,0x00)
请注意,中间值,这是一直在进行的形式,只允许整数红色部分是0x00或0x01。当我们试图保存这个结果回到目的地不规则,划分出阿尔法将给我们进行的非红色值选择很少。在这种情况下,执行在没有捷径的整数空间中执行数学的一个实现,可能会最终与最终的像素值:
(A,R,G,B)=(0x01,0xFF,0x00,0x00)
(注:0x01 0x01给你1分,这相当于在一个8位的存储格式。值0xff)
交替使用,实现浮点运算可能产生更精确的结果,最终返回到原来的像素值很少,如果有的话,舍入误差。或者,使用整数运算实现可能决定,由于方程归结为颜色值虚拟NOP如果浮点空间中进行,它可以传输像素不去目的地,避免所有的数学完全。
这些实现都试图荣誉相同的方程,但使用不同的整数和浮点数学的权衡和减少或全方程。考虑到这种差异,这可能是最好的期待,进行形式的结果之间的匹配实现图像格式。在这种情况下,答案,在表达形式上等同于进行:
(A,R,G,B)=(0x01,0x01,0x00,0x00)
因此,他们将所有的比赛。
Composite
,
CompositeContext
Modifier and Type | Field and Description |
---|---|
static AlphaComposite |
Clear
AlphaComposite 对象实现不透明的明确规则与1.0fα。
|
static int |
CLEAR
无论是色彩和目的地的阿尔法被清除(波特达夫明确的规则)。
|
static AlphaComposite |
Dst
AlphaComposite 对象实现不透明的DST规则与1.0fα。
|
static int |
DST
目的地是原封不动(Porter Duff目的规则)。
|
static int |
DST_ATOP
该目的地躺在里面的源部分复合在源和目的地(目的地在取代Porter Duff来源规则)。
|
static int |
DST_IN
该目的地躺在里面的源部分替代终点(源Porter Duff规则的目的地)。
|
static int |
DST_OUT
该目的地躺源之外的部分替代终点(波特达夫地举行由来源规则)。
|
static int |
DST_OVER
目的是合成过的来源和结果替换目标(Porter Duff目标源的规则)。
|
static AlphaComposite |
DstAtop
AlphaComposite 对象实现不透明dst_atop法则与1.0fα。
|
static AlphaComposite |
DstIn
AlphaComposite 对象实现不透明dst_in法则与1.0fα。
|
static AlphaComposite |
DstOut
AlphaComposite 对象实现不透明dst_out法则与1.0fα。
|
static AlphaComposite |
DstOver
AlphaComposite 对象实现不透明dst_over法则与1.0fα。
|
static AlphaComposite |
Src
AlphaComposite 对象实现不透明的SRC法则与1.0fα。
|
static int |
SRC
源复制到目的地(Porter Duff Source规则)。
|
static int |
SRC_ATOP
躺在里面的源目的地的部分合成到目的地(波特达夫源在目的地规则)。
|
static int |
SRC_IN
躺在里面的源目的地的部分替换目标(目的港规则Porter Duff Source)。
|
static int |
SRC_OUT
的源位于目的地以外的部分替换目标(波特达夫源举行由目的规则)。
|
static int |
SRC_OVER
源是合成过的目的地(Porter Duff源的目标规则)。
|
static AlphaComposite |
SrcAtop
AlphaComposite 对象实现不透明src_atop法则与1.0fα。
|
static AlphaComposite |
SrcIn
AlphaComposite 对象实现不透明src_in法则与1.0fα。
|
static AlphaComposite |
SrcOut
AlphaComposite 对象实现不透明src_out法则与1.0fα。
|
static AlphaComposite |
SrcOver
AlphaComposite 对象实现不透明src_over法则与1.0fα。
|
static AlphaComposite |
Xor
AlphaComposite 对象实现不透明异或规则与1.0fα。
|
static int |
XOR
那就是目的地以外的源的部分结合,在于源之外的目标的一部分(波特达夫源异或目的规则)。
|
Modifier and Type | Method and Description |
---|---|
CompositeContext |
createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints)
创建合成操作上下文。
|
AlphaComposite |
derive(float alpha)
返回一个类似
AlphaComposite 对象使用指定的alpha值。
|
AlphaComposite |
derive(int rule)
返回一个类似
AlphaComposite 对象使用指定的合成规则。
|
boolean |
equals(Object obj)
确定指定的对象是否等于这
AlphaComposite 。
|
float |
getAlpha()
返回该
AlphaComposite α值。
|
static AlphaComposite |
getInstance(int rule)
创建一个具有指定规则
AlphaComposite 对象。
|
static AlphaComposite |
getInstance(int rule, float alpha)
创建一个
AlphaComposite 对象与指定的规则和乘法与源alpha常数α。
|
int |
getRule()
这
AlphaComposite 返回合成规则。
|
int |
hashCode()
返回此复合hashCode。
|
@Native public static final int CLEAR
FS = 0和FD = 0,从而:
AR = 0CR = 0
@Native public static final int SRC
FS = 1和FD = 0,从而:
AR =是CR = CS
@Native public static final int DST
FS = 0和FD = 1,从而:
AR =广告CR = CD
@Native public static final int SRC_OVER
FS = 1和FD =(1-as),因此:
AR = +广告*(1-as)CR = CS + CD(1-as)
@Native public static final int DST_OVER
FS =(1-AD)和FD = 1,从而:
AR = *(1-AD)+广告CR = CS(1-AD)+光盘
@Native public static final int SRC_IN
FS = AD和FD = 0,从而:
作为*广告铬=铯*广告
@Native public static final int DST_IN
FS = 0和FD =,因此:
作为广告=广告铬=镉*为
@Native public static final int SRC_OUT
FS =(1-AD)和FD = 0,从而:
AR = *(1-AD)CR = CS(1-AD)
@Native public static final int DST_OUT
FS = 0和FD =(1-as),因此:
AR =广告*(1-as)CR = CD(1-as)
@Native public static final int SRC_ATOP
FS = AD和FD =(1-as),因此:
AR = *广告+广告*(1-as)=广告CR = CS广告+ CD(1-as)
@Native public static final int DST_ATOP
FS =(1-AD)和FD =,因此:
AR = *(1-AD)+广告* =是CR = CS(1-AD)+光盘*
@Native public static final int XOR
FS =(1-AD)和FD =(1-as),因此:
AR = *(*(1-as 1-AD)+广告)CR = CS(1-AD)+ CD(1-as)
public static final AlphaComposite Clear
AlphaComposite
对象实现不透明的明确规则与1.0fα。
CLEAR
public static final AlphaComposite Src
AlphaComposite
对象实现不透明的SRC法则与1.0fα。
SRC
public static final AlphaComposite Dst
AlphaComposite
对象实现不透明的DST规则与1.0fα。
DST
public static final AlphaComposite SrcOver
AlphaComposite
对象实现不透明src_over法则与1.0fα。
SRC_OVER
public static final AlphaComposite DstOver
AlphaComposite
对象实现不透明dst_over法则与1.0fα。
DST_OVER
public static final AlphaComposite SrcIn
AlphaComposite
对象实现不透明src_in法则与1.0fα。
SRC_IN
public static final AlphaComposite DstIn
AlphaComposite
对象实现不透明dst_in法则与1.0fα。
DST_IN
public static final AlphaComposite SrcOut
AlphaComposite
对象实现不透明src_out法则与1.0fα。
SRC_OUT
public static final AlphaComposite DstOut
AlphaComposite
对象实现不透明dst_out法则与1.0fα。
DST_OUT
public static final AlphaComposite SrcAtop
AlphaComposite
对象实现不透明src_atop法则与1.0fα。
SRC_ATOP
public static final AlphaComposite DstAtop
AlphaComposite
对象实现不透明dst_atop法则与1.0fα。
DST_ATOP
public static final AlphaComposite Xor
AlphaComposite
对象实现不透明异或规则与1.0fα。
XOR
public static AlphaComposite getInstance(int rule)
AlphaComposite
对象。
public static AlphaComposite getInstance(int rule, float alpha)
AlphaComposite
对象与指定的规则和乘法与源alpha常数α。源乘以指定的α在与目标复合。
public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints)
createContext
接口
Composite
srcColorModel
-源的
ColorModel
dstColorModel
-目的地的
ColorModel
hints
,上下文对象之间绘制方案选择提示
CompositeContext
对象被用来进行合成操作。
public float getAlpha()
AlphaComposite
α值。如果这
AlphaComposite
没有alpha值,返回1。
AlphaComposite
α值。
public int getRule()
AlphaComposite
返回合成规则。
AlphaComposite
合成规则。
public AlphaComposite derive(int rule)
AlphaComposite
对象使用指定的合成规则。如果这个对象已经使用指定的合成规则,该对象返回。
public AlphaComposite derive(float alpha)
AlphaComposite
对象使用指定的alpha值。如果此对象已经具有指定的α值,则返回此对象。
alpha
能源的α乘以常数α。
alpha
必须是浮点数的范围 [ 0,1 ]。
AlphaComposite
对象。
IllegalArgumentException
-如果
alpha
小于0或大于1
public int hashCode()
hashCode
方法重写,继承类
Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public boolean equals(Object obj)
AlphaComposite
。
其结果是true
如果只有参数不null
是AlphaComposite
对象具有相同的合成规则和α值为该对象。
equals
方法重写,继承类
Object
obj
-
Object
测试平等
true
如果
obj
等于这
AlphaComposite
;
false
否则。
Object.hashCode()
,
HashMap
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.