问题描述
在Java中,我想使用代码来转换并保存它们,而不是使用photoshop来转换我在程序中使用的图像。
In Java, instead of using photoshop to transform my images(that I use in the program), I want to use code to transform and save them.
I已创建一个在的AffineTransform对象,并调用了 rotate()
方法。我有一个名为 image的BufferedImage。
I have created an AffineTransform object "at" and called the rotate()
method. I have a BufferedImage called "image".
我可以使用以下代码在屏幕上以所需的变换绘制图像:
I can draw the image on the screen with the desired transformation with this code:
g2d.drawImage(image, at, null);
我要做的是将at和image的组合存储在新的BufferedImage image2中。我该怎么做才能使 g2d.drawImage(image2,50,50,null);
将显示图像的旋转版本?
What I want to do is to store the combination of at and image in a new BufferedImage image2. How can I do this so thatg2d.drawImage(image2,50,50, null);
will show the rotated version of image?
编辑:我对Ezequiel的答案做了一些调整,以获得所需的效果。
达到目的:
edit: I've tweaked Ezequiel's answer a bit to get the effect I wanted. This did the trick:
BufferedImage image2= null;
AffineTransformOp affineTransformOp = new AffineTransformOp(at,AffineTransformOp.TYPE_BILINEAR);
image2 = affineTransformOp.filter(image, image2);
g2d.drawImage(image2, 50, 50, null);
推荐答案
使用类:
BufferedImage original; //Instatiate with desired image.
BufferedImage transformed: //Used to store transformed image.
AffineTransform at; //Transformations needed.
AffineTransformOp affineTransformOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
affineTransformOp.filter(original, transformed );
这篇关于在Java中存储转换后的BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!