Java2D - 如何旋转图像并保存结果 [英] Java2D - How to rotate an image and save the result

查看:200
本文介绍了Java2D - 如何旋转图像并保存结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个游戏,其中一些物体旋转以面对他们正在拍摄的东西。拍摄之间有一段延迟,我希望物体保持面对它直到它再次射击。我知道如何加载图像,我知道如何使用AffineTransform旋转它们。但是有了这个,我需要在每次绘制对象时计算旋转。

I'm making a game where some objects rotate to face what they're shooting at. There's a delay in between shooting and I want the object to keep facing where it is until it shoots again. I know how to load images and I know how to rotate them using AffineTransform. But with this I need to calculate the rotate every time the object gets drawn.

所以我的问题是如何旋转图像并将结果保存到新图像中会显示吗?

So my question is how can I rotate an image and save the result into a new image that would get displayed?

推荐答案


如何旋转图像并保存将结果显示在一个可以显示的新图像中?

how can I rotate an image and save the result into a new image that would get displayed?

创建一个新的的BufferedImage 。获取 Graphics 对象(通过 BufferedImage.getGraphics() 。将旋转后的图像绘制到此缓冲图像上,并根据其旋转将图像保存在数组或地图中(以便在需要时轻松查找)。

Create a new BufferedImage. Get hold of a Graphics object (through BufferedImage.getGraphics(). Paint the rotated image onto this buffered image, and save the image in an array or a map based on its rotation (so that it easy to look it up when you need it).

这篇关于Java2D - 如何旋转图像并保存结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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