Java2D - How to rotate an image and save the result(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?
推荐答案
如何旋转图像并将结果保存到可以显示的新图像中?
创建一个新的 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 - 如何旋转图像并保存结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java2D - 如何旋转图像并保存结果


基础教程推荐
- 不推荐使用 Api 注释的描述 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 多个组件的复杂布局 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01