java 保存bufferedimage,在Java中存储转换后的BufferedImage

本文介绍如何在Java中利用AffineTransform对象进行图像旋转,并将旋转后的图像保存为新的BufferedImage对象。通过AffineTransformOp过滤器实现图像变换,以便后续在屏幕上显示或进一步处理。
摘要由CSDN通过智能技术生成

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

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值