Java2D - 如何旋转图像并保存结果

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

本文介绍了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 - 如何旋转图像并保存结果

基础教程推荐