public static BufferedImage cropImage(BufferedImage bi, int x, int y, int w, int h) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); g2.fillRect(0, 0, w, h); g2.drawImage(bi, -x, -y, null); // this); g2.dispose(); return image; }
public static BufferedImage scaleImage(BufferedImage bi, double scale) { int w1 = (int) (Math.round(scale * bi.getWidth())); int h1 = (int) (Math.round(scale * bi.getHeight())); BufferedImage image = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); g2.fillRect(0, 0, w1, h1); g2.drawImage(bi, 0, 0, w1, h1, null); // this); g2.dispose(); return image; }
public static BufferedImage rotateImage(BufferedImage bi) { int w = bi.getWidth(); int h = bi.getHeight(); BufferedImage image = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); // getBackground()); g2.fillRect(0, 0, h, w); g2.rotate(90 * Math.PI / 180); g2.drawImage(bi, 0, -h, w, h, null); // this); g2.dispose(); return image; }
/** [Advanced] */ public void dispose() { Graphics2D g = getG(); if (g != null) g.dispose(); }