storing transformed BufferedImage in Java

萝らか妹 提交于 2020-01-04 06:48:49

问题


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 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);

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?

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);

回答1:


With AffineTransformOp class:

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 );


来源:https://stackoverflow.com/questions/26487614/storing-transformed-bufferedimage-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!