将新的BufferedImage传递给filter()方法,而不是让它创建自己的工作(不是完全黑色).
此外,转换似乎无法正常工作,图像最终在目标中偏移.我能够通过手动应用必要的翻译来修复它,按相反顺序记录这些工作,并在目标图像中宽度=旧高度,高度=旧宽度.
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.