gpt4 book ai didi

Java:旋转图像

转载 作者:太空狗 更新时间:2023-10-29 22:49:31 31 4
gpt4 key购买 nike

我需要能够单独旋转图像(在 Java 中)。到目前为止我唯一发现的是 g2d.drawImage(image, affinetransform, ImageObserver )。不幸的是,我需要在特定点绘制图像,并且没有方法的参数是 1. 单独旋转图像和 2. 允许我设置 x 和 y。感谢任何帮助

最佳答案

这就是您可以做到的。此代码假定存在名为“图像”的缓冲图像(如您的评论所述)

// The required drawing location
int drawLocationX = 300;
int drawLocationY = 300;

// Rotation information

double rotationRequired = Math.toRadians (45);
double locationX = image.getWidth() / 2;
double locationY = image.getHeight() / 2;
AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);

// Drawing the rotated image at the required drawing locations
g2d.drawImage(op.filter(image, null), drawLocationX, drawLocationY, null);

关于Java:旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8639567/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com