public static final int J2D_ROTATE_90 = 90; public static final int J2D_ROTATE_180 = 180; public static final int J2D_ROTATE_270 = 270; /** * 旋转 - 参数指定目标图旋转角度。 * @param bufferedImage BufferedImage * @param radian int * @param hints RenderingHints * @return BufferedImage */ public static BufferedImage rotateJ2D(BufferedImage bufferedImage, int radian, RenderingHints hints) { int width = bufferedImage.getWidth(); int height = bufferedImage.getHeight(); BufferedImage dstImage = null; AffineTransform affineTransform = new AffineTransform(); if (radian == 180) { affineTransform.translate(width, height); dstImage = new BufferedImage(width, height, bufferedImage.getType()); } else if (radian == 90) { affineTransform.translate(height, 0); dstImage = new BufferedImage(height, width, bufferedImage.getType()); } else if (radian == 270) { affineTransform.translate(0, width); dstImage = new BufferedImage(height, width, bufferedImage.getType()); } affineTransform.rotate(java.lang.Math.toRadians(radian)); AffineTransformOp affineTransformOp = new AffineTransformOp( affineTransform, hints); return affineTransformOp.filter(bufferedImage, dstImage); }
本文转自:http://topic.csdn.net/t/20060712/15/4875844.html
如果你喜欢本文, 请长按二维码,关注公众号 分布式编程. 作者:分布式编程 出处:https://zthinker.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。