java旋转图片后边上变黑_使用AffineTransform的Java图像旋转输出黑色图像,但是在调整大小时效果很好...

小编典典

将新的BufferedImage传递到filter()方法中,而不是让它创建自己的作品(不是完全黑色)。

同样,变换似乎无法正常工作,图像最终在目标中偏移了。我能够通过手动应用必要的转换来解决它,以相反的顺序记录这些工作,并且在目标图像中,width

=旧高度,而height =旧宽度。

AffineTransform tx = new AffineTransform();

// last, width = height and height = width :)

tx.translate(originalImage.getHeight() / 2,originalImage.getWidth() / 2);

tx.rotate(Math.PI / 2);

// first - center image at the origin so rotate works OK

tx.translate(-originalImage.getWidth() / 2,-originalImage.getHeight() / 2);

AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);

// new destination image where height = width and width = height.

BufferedImage newImage =new BufferedImage(originalImage.getHeight(), originalImage.getWidth(), originalImage.getType());

op.filter(originalImage, newImage);

filter()的javadoc声明它将为您创建BufferedImage,我仍然不确定为什么它不起作用,这里肯定有问题。

If the destination image is null, a BufferedImage is created with the source ColorModel.

2020-10-12

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值