下面列出了java.awt.AlphaComposite#getAlpha ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Record information about drawing done
* with the supplied <code>Composite</code>.
*/
private void checkAlpha(Composite composite) {
if (composite instanceof AlphaComposite) {
AlphaComposite alphaComposite = (AlphaComposite) composite;
float alpha = alphaComposite.getAlpha();
int rule = alphaComposite.getRule();
if (alpha != 1.0
|| (rule != AlphaComposite.SRC
&& rule != AlphaComposite.SRC_OVER)) {
mHasCompositing = true;
}
} else {
mHasCompositing = true;
}
}
/**
* Record information about drawing done
* with the supplied {@code Composite}.
*/
private void checkAlpha(Composite composite) {
if (composite instanceof AlphaComposite) {
AlphaComposite alphaComposite = (AlphaComposite) composite;
float alpha = alphaComposite.getAlpha();
int rule = alphaComposite.getRule();
if (alpha != 1.0
|| (rule != AlphaComposite.SRC
&& rule != AlphaComposite.SRC_OVER)) {
mHasCompositing = true;
}
} else {
mHasCompositing = true;
}
}
/**
* Method contributed by Alexej Suchov
*
* @see Graphics2D#setComposite(Composite)
*/
@Override
public void setComposite(Composite comp) {
if (comp instanceof AlphaComposite) {
AlphaComposite composite = (AlphaComposite) comp;
if (composite.getRule() == 3) {
alpha = composite.getAlpha();
this.composite = composite;
if (realPaint != null && realPaint instanceof Color) {
Color c = (Color) realPaint;
paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (c.getAlpha() * alpha));
}
return;
}
}
composite = comp;
alpha = 1.0F;
}
/**
* Record information about drawing done
* with the supplied <code>Composite</code>.
*/
private void checkAlpha(Composite composite) {
if (composite instanceof AlphaComposite) {
AlphaComposite alphaComposite = (AlphaComposite) composite;
float alpha = alphaComposite.getAlpha();
int rule = alphaComposite.getRule();
if (alpha != 1.0
|| (rule != AlphaComposite.SRC
&& rule != AlphaComposite.SRC_OVER)) {
mHasCompositing = true;
}
} else {
mHasCompositing = true;
}
}
/**
* Record information about drawing done
* with the supplied <code>Composite</code>.
*/
private void checkAlpha(Composite composite) {
if (composite instanceof AlphaComposite) {
AlphaComposite alphaComposite = (AlphaComposite) composite;
float alpha = alphaComposite.getAlpha();
int rule = alphaComposite.getRule();
if (alpha != 1.0
|| (rule != AlphaComposite.SRC
&& rule != AlphaComposite.SRC_OVER)) {
mHasCompositing = true;
}
} else {
mHasCompositing = true;
}
}
/**
* Record information about drawing done
* with the supplied <code>Composite</code>.
*/
private void checkAlpha(Composite composite) {
if (composite instanceof AlphaComposite) {
AlphaComposite alphaComposite = (AlphaComposite) composite;
float alpha = alphaComposite.getAlpha();
int rule = alphaComposite.getRule();
if (alpha != 1.0
|| (rule != AlphaComposite.SRC
&& rule != AlphaComposite.SRC_OVER)) {
mHasCompositing = true;
}
} else {
mHasCompositing = true;
}
}
/**
* Method contributed by Alexej Suchov
* @see Graphics2D#setComposite(Composite)
*/
public void setComposite(Composite comp) {
if (comp instanceof AlphaComposite) {
AlphaComposite composite = (AlphaComposite) comp;
if (composite.getRule() == 3) {
alpha = composite.getAlpha();
this.composite = composite;
if (realPaint != null && (realPaint instanceof Color)) {
Color c = (Color) realPaint;
paint = new Color(c.getRed(), c.getGreen(), c.getBlue(),
(int) (c.getAlpha() * alpha));
}
return;
}
}
this.composite = comp;
alpha = 1.0F;
}
/**
* Record information about drawing done
* with the supplied {@code Composite}.
*/
private void checkAlpha(Composite composite) {
if (composite instanceof AlphaComposite) {
AlphaComposite alphaComposite = (AlphaComposite) composite;
float alpha = alphaComposite.getAlpha();
int rule = alphaComposite.getRule();
if (alpha != 1.0
|| (rule != AlphaComposite.SRC
&& rule != AlphaComposite.SRC_OVER)) {
mHasCompositing = true;
}
} else {
mHasCompositing = true;
}
}
/**
* Record information about drawing done
* with the supplied <code>Composite</code>.
*/
private void checkAlpha(Composite composite) {
if (composite instanceof AlphaComposite) {
AlphaComposite alphaComposite = (AlphaComposite) composite;
float alpha = alphaComposite.getAlpha();
int rule = alphaComposite.getRule();
if (alpha != 1.0
|| (rule != AlphaComposite.SRC
&& rule != AlphaComposite.SRC_OVER)) {
mHasCompositing = true;
}
} else {
mHasCompositing = true;
}
}
/**
* Return a CompositeType object for the specified AlphaComposite
* rule.
*/
public static CompositeType forAlphaComposite(AlphaComposite ac) {
switch (ac.getRule()) {
case AlphaComposite.CLEAR:
return Clear;
case AlphaComposite.SRC:
if (ac.getAlpha() >= 1.0f) {
return SrcNoEa;
} else {
return Src;
}
case AlphaComposite.DST:
return Dst;
case AlphaComposite.SRC_OVER:
if (ac.getAlpha() >= 1.0f) {
return SrcOverNoEa;
} else {
return SrcOver;
}
case AlphaComposite.DST_OVER:
return DstOver;
case AlphaComposite.SRC_IN:
return SrcIn;
case AlphaComposite.DST_IN:
return DstIn;
case AlphaComposite.SRC_OUT:
return SrcOut;
case AlphaComposite.DST_OUT:
return DstOut;
case AlphaComposite.SRC_ATOP:
return SrcAtop;
case AlphaComposite.DST_ATOP:
return DstAtop;
case AlphaComposite.XOR:
return AlphaXor;
default:
throw new InternalError("Unrecognized alpha rule");
}
}
/**
* Sets the current composite. This implementation currently supports
* only the {@link AlphaComposite} class.
*
* @param comp the composite (<code>null</code> not permitted).
*/
public void setComposite(Composite comp) {
if (comp == null) {
throw new IllegalArgumentException("Null 'comp' argument.");
}
this.composite = comp;
if (comp instanceof AlphaComposite) {
AlphaComposite acomp = (AlphaComposite) comp;
int alpha = (int) (acomp.getAlpha() * 0xFF);
this.gc.setAlpha(alpha);
}
}
/**
* Return a CompositeType object for the specified AlphaComposite
* rule.
*/
public static CompositeType forAlphaComposite(AlphaComposite ac) {
switch (ac.getRule()) {
case AlphaComposite.CLEAR:
return Clear;
case AlphaComposite.SRC:
if (ac.getAlpha() >= 1.0f) {
return SrcNoEa;
} else {
return Src;
}
case AlphaComposite.DST:
return Dst;
case AlphaComposite.SRC_OVER:
if (ac.getAlpha() >= 1.0f) {
return SrcOverNoEa;
} else {
return SrcOver;
}
case AlphaComposite.DST_OVER:
return DstOver;
case AlphaComposite.SRC_IN:
return SrcIn;
case AlphaComposite.DST_IN:
return DstIn;
case AlphaComposite.SRC_OUT:
return SrcOut;
case AlphaComposite.DST_OUT:
return DstOut;
case AlphaComposite.SRC_ATOP:
return SrcAtop;
case AlphaComposite.DST_ATOP:
return DstAtop;
case AlphaComposite.XOR:
return AlphaXor;
default:
throw new InternalError("Unrecognized alpha rule");
}
}
private boolean canHandleComposite(Composite c) {
if (c instanceof AlphaComposite) {
AlphaComposite ac = (AlphaComposite)c;
return ac.getRule() == AlphaComposite.SRC_OVER && ac.getAlpha() >= 1f;
}
return false;
}
/**
* Return a CompositeType object for the specified AlphaComposite
* rule.
*/
public static CompositeType forAlphaComposite(AlphaComposite ac) {
switch (ac.getRule()) {
case AlphaComposite.CLEAR:
return Clear;
case AlphaComposite.SRC:
if (ac.getAlpha() >= 1.0f) {
return SrcNoEa;
} else {
return Src;
}
case AlphaComposite.DST:
return Dst;
case AlphaComposite.SRC_OVER:
if (ac.getAlpha() >= 1.0f) {
return SrcOverNoEa;
} else {
return SrcOver;
}
case AlphaComposite.DST_OVER:
return DstOver;
case AlphaComposite.SRC_IN:
return SrcIn;
case AlphaComposite.DST_IN:
return DstIn;
case AlphaComposite.SRC_OUT:
return SrcOut;
case AlphaComposite.DST_OUT:
return DstOut;
case AlphaComposite.SRC_ATOP:
return SrcAtop;
case AlphaComposite.DST_ATOP:
return DstAtop;
case AlphaComposite.XOR:
return AlphaXor;
default:
throw new InternalError("Unrecognized alpha rule");
}
}
/**
* Return a CompositeType object for the specified AlphaComposite
* rule.
*/
public static CompositeType forAlphaComposite(AlphaComposite ac) {
switch (ac.getRule()) {
case AlphaComposite.CLEAR:
return Clear;
case AlphaComposite.SRC:
if (ac.getAlpha() >= 1.0f) {
return SrcNoEa;
} else {
return Src;
}
case AlphaComposite.DST:
return Dst;
case AlphaComposite.SRC_OVER:
if (ac.getAlpha() >= 1.0f) {
return SrcOverNoEa;
} else {
return SrcOver;
}
case AlphaComposite.DST_OVER:
return DstOver;
case AlphaComposite.SRC_IN:
return SrcIn;
case AlphaComposite.DST_IN:
return DstIn;
case AlphaComposite.SRC_OUT:
return SrcOut;
case AlphaComposite.DST_OUT:
return DstOut;
case AlphaComposite.SRC_ATOP:
return SrcAtop;
case AlphaComposite.DST_ATOP:
return DstAtop;
case AlphaComposite.XOR:
return AlphaXor;
default:
throw new InternalError("Unrecognized alpha rule");
}
}
/**
* Sets the current composite. This implementation currently supports
* only the {@link AlphaComposite} class.
*
* @param comp the composite.
*/
public void setComposite(Composite comp) {
this.composite = comp;
if (comp instanceof AlphaComposite) {
AlphaComposite acomp = (AlphaComposite) comp;
int alpha = (int) (acomp.getAlpha() * 0xFF);
this.gc.setAlpha(alpha);
}
else {
System.out.println("warning, can only handle alpha composite at the moment.");
}
}
/**
* Return a CompositeType object for the specified AlphaComposite
* rule.
*/
public static CompositeType forAlphaComposite(AlphaComposite ac) {
switch (ac.getRule()) {
case AlphaComposite.CLEAR:
return Clear;
case AlphaComposite.SRC:
if (ac.getAlpha() >= 1.0f) {
return SrcNoEa;
} else {
return Src;
}
case AlphaComposite.DST:
return Dst;
case AlphaComposite.SRC_OVER:
if (ac.getAlpha() >= 1.0f) {
return SrcOverNoEa;
} else {
return SrcOver;
}
case AlphaComposite.DST_OVER:
return DstOver;
case AlphaComposite.SRC_IN:
return SrcIn;
case AlphaComposite.DST_IN:
return DstIn;
case AlphaComposite.SRC_OUT:
return SrcOut;
case AlphaComposite.DST_OUT:
return DstOut;
case AlphaComposite.SRC_ATOP:
return SrcAtop;
case AlphaComposite.DST_ATOP:
return DstAtop;
case AlphaComposite.XOR:
return AlphaXor;
default:
throw new InternalError("Unrecognized alpha rule");
}
}
/**
* Sets the current composite. This implementation currently supports
* only the {@link AlphaComposite} class.
*
* @param comp the composite (<code>null</code> not permitted).
*/
public void setComposite(Composite comp) {
if (comp == null) {
throw new IllegalArgumentException("Null 'comp' argument.");
}
this.composite = comp;
if (comp instanceof AlphaComposite) {
AlphaComposite acomp = (AlphaComposite) comp;
int alpha = (int) (acomp.getAlpha() * 0xFF);
this.gc.setAlpha(alpha);
}
}
/**
* Return a CompositeType object for the specified AlphaComposite
* rule.
*/
public static CompositeType forAlphaComposite(AlphaComposite ac) {
switch (ac.getRule()) {
case AlphaComposite.CLEAR:
return Clear;
case AlphaComposite.SRC:
if (ac.getAlpha() >= 1.0f) {
return SrcNoEa;
} else {
return Src;
}
case AlphaComposite.DST:
return Dst;
case AlphaComposite.SRC_OVER:
if (ac.getAlpha() >= 1.0f) {
return SrcOverNoEa;
} else {
return SrcOver;
}
case AlphaComposite.DST_OVER:
return DstOver;
case AlphaComposite.SRC_IN:
return SrcIn;
case AlphaComposite.DST_IN:
return DstIn;
case AlphaComposite.SRC_OUT:
return SrcOut;
case AlphaComposite.DST_OUT:
return DstOut;
case AlphaComposite.SRC_ATOP:
return SrcAtop;
case AlphaComposite.DST_ATOP:
return DstAtop;
case AlphaComposite.XOR:
return AlphaXor;
default:
throw new InternalError("Unrecognized alpha rule");
}
}
/**
* Sets the <code>Composite</code> for the <code>Graphics2D</code> context. The <code>Composite</code> is used in all
* drawing methods such as <code>drawImage</code>, <code>drawString</code>, <code>draw</code>, and <code>fill</code>.
* It specifies how new pixels are to be combined with the existing pixels on the graphics device during the rendering
* process.
* <p>
* If this <code>Graphics2D</code> context is drawing to a <code>Component</code> on the display screen and the
* <code>Composite</code> is a custom object rather than an instance of the <code>AlphaComposite</code> class, and if
* there is a security manager, its <code>checkPermission</code> method is called with an
* <code>AWTPermission("readDisplayPixels")</code> permission.
*
* @param comp
* the <code>Composite</code> object to be used for rendering
* @throws SecurityException
* if a custom <code>Composite</code> object is being used to render to the screen and a security manager is
* set and its <code>checkPermission</code> method does not allow the operation.
* @see java.awt.Graphics#setXORMode
* @see java.awt.Graphics#setPaintMode
* @see #getComposite
* @see java.awt.AlphaComposite
* @see SecurityManager#checkPermission
* @see java.awt.AWTPermission
*/
public void setComposite( final Composite comp ) {
if ( comp instanceof AlphaComposite ) {
final AlphaComposite composite = (AlphaComposite) comp;
if ( composite.getRule() == 3 ) {
alpha = composite.getAlpha();
this.composite = composite;
if ( realPaint != null && ( realPaint instanceof Color ) ) {
final Color c = (Color) realPaint;
paint = new Color( c.getRed(), c.getGreen(), c.getBlue(), (int) ( (float) c.getAlpha() * alpha ) );
}
return;
}
}
this.composite = comp;
alpha = 1.0F;
}