Java实现图片旋转、指定图像大小和水平翻转
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Java实现图⽚旋转、指定图像⼤⼩和⽔平翻转本⽂实例为⼤家分享了Java实现图⽚旋转、指定图像⼤⼩、⽔平翻转,供⼤家参考,具体内容如下
package com.zeph.j2se.image;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
public class ImageOperate {
/**
* 旋转图⽚为指定⾓度
*
* @param bufferedimage
* ⽬标图像
* @param degree
* 旋转⾓度
* @return
*/
public static BufferedImage rotateImage(final BufferedImage bufferedimage,
final int degree) {
int w = bufferedimage.getWidth();
int h = bufferedimage.getHeight();
int type = bufferedimage.getColorModel().getTransparency();
BufferedImage img;
Graphics2D graphics2d;
(graphics2d = (img = new BufferedImage(w, h, type)).createGraphics())
.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2d.rotate(Math.toRadians(degree), w / 2, h / 2);
graphics2d.drawImage(bufferedimage, 0, 0, null);
graphics2d.dispose();
return img;
}
/**
* 变更图像为指定⼤⼩
*
* @param bufferedimage
* ⽬标图像
* @param w
* 宽
* @param h
* ⾼
* @return
*/
public static BufferedImage resizeImage(final BufferedImage bufferedimage,
final int w, final int h) {
int type = bufferedimage.getColorModel().getTransparency();
BufferedImage img;
Graphics2D graphics2d;
(graphics2d = (img = new BufferedImage(w, h, type)).createGraphics())
.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2d.drawImage(bufferedimage, 0, 0, w, h, 0, 0,
bufferedimage.getWidth(), bufferedimage.getHeight(), null);
graphics2d.dispose();
return img;
}
/**
* ⽔平翻转图像
*
* @param bufferedimage
* ⽬标图像
* @return
*/
public static BufferedImage flipImage(final BufferedImage bufferedimage) {
int w = bufferedimage.getWidth();
int h = bufferedimage.getHeight();
BufferedImage img;
Graphics2D graphics2d;
(graphics2d = (img = new BufferedImage(w, h, bufferedimage
.getColorModel().getTransparency())).createGraphics())
.drawImage(bufferedimage, 0, 0, w, h, w, 0, 0, h, null);
graphics2d.dispose();
return img;
}
}
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。