本文整理汇总了Java中sun.java2d.SunGraphics2D.setComposite方法的典型用法代码示例。如果您正苦于以下问题:Java SunGraphics2D.setComposite方法的具体用法?Java SunGraphics2D.setComposite怎么用?Java SunGraphics2D.setComposite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.java2d.SunGraphics2D
的用法示例。
在下文中一共展示了SunGraphics2D.setComposite方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeBufferedImage
import sun.java2d.SunGraphics2D; //导入方法依赖的package包/类
/**
* Return a non-accelerated BufferedImage of the requested type with the
* indicated subimage of the original image located at 0,0 in the new image.
* If a bgColor is supplied, composite the original image over that color
* with a SrcOver operation, otherwise make a SrcNoEa copy.
* <p>
* Returned BufferedImage is not accelerated for two reasons:
* <ul>
* <li> Types of the image and surface are predefined, because these types
* correspond to the TransformHelpers, which we know we have. And
* acceleration can change the type of the surface
* <li> Image will be used only once and acceleration caching wouldn't help
* </ul>
*/
BufferedImage makeBufferedImage(Image img, Color bgColor, int type,
int sx1, int sy1, int sx2, int sy2)
{
final int width = sx2 - sx1;
final int height = sy2 - sy1;
final BufferedImage bimg = new BufferedImage(width, height, type);
final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics();
g2d.setComposite(AlphaComposite.Src);
bimg.setAccelerationPriority(0);
if (bgColor != null) {
g2d.setColor(bgColor);
g2d.fillRect(0, 0, width, height);
g2d.setComposite(AlphaComposite.SrcOver);
}
g2d.copyImage(img, 0, 0, sx1, sy1, width, height, null, null);
g2d.dispose();
return bimg;
}
示例2: makeBufferedImage
import sun.java2d.SunGraphics2D; //导入方法依赖的package包/类
/**
* Return a non-accelerated BufferedImage of the requested type with the
* indicated subimage of the original image located at 0,0 in the new image.
* If a bgColor is supplied, composite the original image over that color
* with a SrcOver operation, otherwise make a SrcNoEa copy.
* <p>
* Returned BufferedImage is not accelerated for two reasons:
* <ul>
* <li> Types of the image and surface are predefined, because these types
* correspond to the TransformHelpers, which we know we have. And
* acceleration can change the type of the surface
* <li> Image will be used only once and acceleration caching wouldn't help
* </ul>
*/
private BufferedImage makeBufferedImage(Image img, Color bgColor, int type,
int sx1, int sy1, int sx2, int sy2)
{
final int width = sx2 - sx1;
final int height = sy2 - sy1;
final BufferedImage bimg = new BufferedImage(width, height, type);
final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics();
g2d.setComposite(AlphaComposite.Src);
bimg.setAccelerationPriority(0);
if (bgColor != null) {
g2d.setColor(bgColor);
g2d.fillRect(0, 0, width, height);
g2d.setComposite(AlphaComposite.SrcOver);
}
g2d.copyImage(img, 0, 0, sx1, sy1, width, height, null, null);
g2d.dispose();
return bimg;
}