在另一个图像下旋转一个图像 [英] Rotating one image under another one

查看:169
本文介绍了在另一个图像下旋转一个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试旋转图像,然后在顶部绘制一个不旋转的图像。但每当我使用:
g2d.rotate(Math.toRadians(rot),(x + 15),(y + 15));
我之后绘制的每个图像也会旋转。有什么方法可以旋转一个图像而不是旋转其余的图像(这真的很难解释)。
这是我的绘画方法:

I am currently trying to rotate an image and then drawing an image on top which isn't rotating. But whenever I use: g2d.rotate(Math.toRadians(rot), (x+15), (y+15)); every image I draw afterwards rotates as well. Is there any way I can rotate one image and not rotate the rest (gosh its really hard to explain). Here's my paint method:

public void draw(Graphics2D g2d)
{
    move();
    if(bo.px==+1)rot--;
    if(bo.px==-1)rot++;
    g2d.rotate(Math.toRadians(rot), (x+15), (y+15));
    g2d.drawImage(img, x, y, null);//this should rotate
    g2d.drawImage(shine, x, y, null);//this shouldn't
}

提前致谢。

推荐答案

您可以保存原始变换,旋转并绘制第一个图像,然后在绘制第二个图像之前应用原始变换。

You can save the original transform, rotate and draw the first image and then apply back the original transform before drawing the second image.

尝试

AffineTransform originalTransform = g2d.getTransform();
g2d.rotate(Math.toRadians(rot), (x+15), (y+15));
g2d.drawImage(img, x, y, null);
g2d.setTransform(originalTransform);
g2d.drawImage(shine, x, y, null);

这篇关于在另一个图像下旋转一个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆