java graphics setcolor_Java SunGraphics2D.setColor方法代码示例

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.

*

* Returned BufferedImage is not accelerated for two reasons:

*

*

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

*

Image will be used only once and acceleration caching wouldn't help

*

*/

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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值