Java中Image的水平翻转、缩放与自由旋转操作
2017-08-17 17:41
253 查看
bufferedimage.getColorModel().getTransparency()以获得原始图片透明度用于生成缓存图,在缓存图进行相应操作即可。
/**
* 旋转图片为指定角度
*
* @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 = createImage(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 = createImage(w, h, bufferedimage
.getColorModel().getTransparency())).createGraphics())
.drawImage(bufferedimage, 0, 0, w, h, w, 0, 0, h, null);
graphics2d.dispose();
return img;
}
/**
* 旋转图片为指定角度
*
* @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 = createImage(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 = createImage(w, h, bufferedimage
.getColorModel().getTransparency())).createGraphics())
.drawImage(bufferedimage, 0, 0, w, h, w, 0, 0, h, null);
graphics2d.dispose();
return img;
}
相关文章推荐
- 转:Java中Image的水平翻转、缩放与自由旋转操作
- Java中Image的水平翻转、缩放与自由旋转操作
- Java中Image的水平翻转、缩放与自由旋转操作
- Java中Image的水平翻转、缩放与自由旋转操作
- java图片旋转,缩放,翻转
- 自定义Imageview控件实现多种手势操作 (拖动、水平缩放、竖直缩放、等比例缩放、双击、长按)
- 【Android】自定义ImageView实现图片的平移、缩放、旋转(手势操作)
- Qt5:Qt中图片的翻转,旋转,缩放,扭曲操作
- Java的图像旋转 指定图像大小 水平翻转图像
- UIKit 图片的移动、位移、旋转、缩放、翻转、翻页等特效的使用
- 用QMatrix实现帧的旋转、翻转、放大、缩小等简单操作示例
- Android单点触控技术,对图片进行平移,缩放,旋转操作
- JAVA对图片的任意角度旋转,以及镜像操作
- Android单点触控技术,对图片进行平移,缩放,旋转操作
- php图片处理代码分享,包括缩放、剪裁、缩放、翻转、旋转、透明、锐化等
- 矩阵操作-flip(垂直,水平或即垂直又水平翻转二维数组)
- ImageView实现图片旋转和缩放
- Android Bitmap 常见的几个操作:缩放,裁剪,旋转,偏移
- iOS 使用手势UIGestureRecognizer对图像进行缩放、移动、旋转操作
- 操作图像4-pillow-旋转,翻转图像、更改单个元素