List of utility methods to do Image Rotate
BufferedImage | imageRotate(Image img, int angle) image Rotate BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = (Graphics2D) bi.getGraphics(); graphics.rotate(Math.toRadians(angle), 26, 26); graphics.drawImage(img, 0, 0, null); graphics.dispose(); return bi; |
File | rotate(File sourceImage, String targetImageName, double degree) rotate String extentionName = getExtentionName(sourceImage.getName()); if (extentionName != null && isASupportedImageType(extentionName)) { try { return doRotate(sourceImage, targetImageName, Math.toRadians(degree)); } catch (IOException e) { return null; } else { ... |
Image | rotate(Image image, double angle) Rotates an Image object. BufferedImage bufImg = toBufferedImage(image); double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); int w = bufImg.getWidth(), h = bufImg.getHeight(); int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin); BufferedImage result = new BufferedImage(neww, newh, Transparency.TRANSLUCENT); Graphics2D g = result.createGraphics(); g.translate((neww - w) / 2, (newh - h) / 2); g.rotate(angle, w / 2, h / 2); ... |
Image | rotate(Image img, double angle) Rota una imagen. double sin = Math.abs(Math.sin(Math.toRadians(angle))), cos = Math.abs(Math.cos(Math.toRadians(angle))); int w = img.getWidth(null); int h = img.getHeight(null); int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin); BufferedImage bimg = toBufferedImage(getEmptyImage(neww, newh)); Graphics2D g = bimg.createGraphics(); g.translate((neww - w) / 2, (newh - h) / 2); g.rotate(Math.toRadians(angle), w / 2, h / 2); ... |
Image | rotate(Image img, double angle) Rotates an image. double sin = Math.abs(Math.sin(Math.toRadians(angle))), cos = Math.abs(Math.cos(Math.toRadians(angle))); int w = img.getWidth(null), h = img.getHeight(null); int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin); BufferedImage bimg = toBufferedImage(getEmptyImage(neww, newh)); Graphics2D g = bimg.createGraphics(); g.translate((neww - w) / 2, (newh - h) / 2); g.rotate(Math.toRadians(angle), w / 2, h / 2); g.drawRenderedImage(toBufferedImage(img), null); ... |
Image | rotate(Image img, float radian) rotate if (img == null) { return null; int width = img.getWidth(null); int height = img.getHeight(null); BufferedImage bufImage = null; if (img instanceof BufferedImage) { bufImage = (BufferedImage) img; ... |
BufferedImage | Rotate(Image src, int angel) Rotate int src_width = src.getWidth(null); int src_height = src.getHeight(null); Rectangle rect_des = CalcRotatedSize(new Rectangle(new Dimension(src_width, src_height)), angel); BufferedImage res = null; res = new BufferedImage(rect_des.width, rect_des.height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = res.createGraphics(); g2.translate((rect_des.width - src_width) / 2, (rect_des.height - src_height) / 2); g2.rotate(Math.toRadians(angel), src_width / 2, src_height / 2); ... |
File | rotateImage(final File imagePath, int numquadrants) Return image rotated as tempFile try { BufferedImage bufferedImage = ImageIO.read(imagePath); bufferedImage = transform(bufferedImage, numquadrants); File outputfile = Files.createTempFile("temp", "png").toFile(); ImageIO.write(bufferedImage, "png", outputfile); return outputfile; } catch (IOException ex) { return null; |
AffineTransform | rotateImage(final Image img, final Point location, final double degrees) Returns a rotated AffineTransform object that can be used to rotate an image. AffineTransform affine = new AffineTransform(); affine.setToTranslation(location.getX(), location.getY()); affine.rotate(Math.toRadians(degrees), img.getWidth(null) / 2, img.getHeight(null) / 2); return affine; |
BufferedImage | rotateImage(Image inImage, int inMaxWidth, int inMaxHeight, int inRotationDegrees) Create a new image by rotating and scaling the given one boolean isRotated = (inRotationDegrees % 180 != 0); int origWidth = inImage.getWidth(null); int origHeight = inImage.getHeight(null); int thumbWidth = isRotated ? origHeight : origWidth; int thumbHeight = isRotated ? origWidth : origHeight; Dimension scaledSize = getThumbnailSize(thumbWidth, thumbHeight, inMaxWidth, inMaxHeight); BufferedImage result = new BufferedImage(scaledSize.width, scaledSize.height, BufferedImage.TYPE_INT_RGB); if (inRotationDegrees == 0) { ... |