且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

旋转BufferedImage时如何产生清晰的绘画效果?

更新时间:2023-12-05 17:07:34

旋转光栅化图像(例如BufferedImage)时,会丢失数据。***的解决方案是保存比您需要的图像更大的图像,并在绘制时动态缩小图像。我发现你所需尺寸的1.5倍是一个很好的起点。

When you rotate a rasterized image (such as a BufferedImage), you lose data. The best solution is to save your images larger than you'll need them, and downscale on the fly when you paint them. I've found that 1.5x the size you need is a good starting point.

然后,当你在绘制图像时,立即调整大小:

Then, when you're painting the image, resize on the fly:

g.drawImage(bufferedImage, x, y, desiredWidth, desiredHeight, observer);

建议使用双线性插值进行旋转。

建议的信用额转到guido。