List of usage examples for java.awt.image AffineTransformOp AffineTransformOp
public AffineTransformOp(AffineTransform xform, int interpolationType)
From source file:paintbasico2d.VentanaPrincipal.java
private void jButton270gradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton270gradosActionPerformed // TODO add your handling code here: VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame()); if (vi != null) { BufferedImage ImgSource = vi.getLienzo().getImage(); if (ImgSource != null) { double r = Math.toRadians(270); Point p = new Point(ImgSource.getWidth() / 2, ImgSource.getHeight() / 2); AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y); try { AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); BufferedImage imgdest = atop.filter(ImgSource, null); vi.getLienzo().setImage(imgdest); vi.getLienzo().repaint(); } catch (Exception e) { System.err.println("error"); }// w w w . ja va 2 s . c o m } } }
From source file:paintbasico2d.VentanaPrincipal.java
private void jButton90gradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton90gradosActionPerformed VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame()); if (vi != null) { BufferedImage ImgSource = vi.getLienzo().getImage(); if (ImgSource != null) { double r = Math.toRadians(90); Point p = new Point(ImgSource.getWidth() / 2, ImgSource.getHeight() / 2); AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y); try { AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); BufferedImage imgdest = atop.filter(ImgSource, null); vi.getLienzo().setImage(imgdest); vi.getLienzo().repaint(); } catch (Exception e) { System.err.println("error"); }/*from ww w. java2s . co m*/ } } }
From source file:paintbasico2d.VentanaPrincipal.java
private void jSliderRotacionStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderRotacionStateChanged VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame()); if (vi != null) { BufferedImage ImgSource = vi.getLienzo().getImage(); if (img == null) img = ImgSource;// w w w . ja v a 2 s. com if (ImgSource != null) { try { double r = Math.toRadians(jSliderRotacion.getValue()); Point p = new Point(img.getWidth(null) / 2, img.getWidth(null) / 2); AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y); AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); BufferedImage imgdest = atop.filter(img, null); vi.getLienzo().setImage(imgdest); vi.getLienzo().repaint(); } catch (Exception e) { System.err.println("error"); } } } }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Scale the given {@code source} {@link Image}. * * @param source Source image.//ww w . j a v a 2 s . c o m * @param width New width. * @param height New height. * * @return Scaled {@code source} image (uses bilinear interpolation). */ public static BufferedImage getScaledImage(Image source, int width, int height) { // convert the given Image into a BufferedImage if needed--makes things a // little easier. BufferedImage image; if (source instanceof BufferedImage) { image = (BufferedImage) source; } else { image = new BufferedImage(source.getWidth(null), source.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.drawImage(source, 0, 0, null); g.dispose(); } int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); double scaleX = (double) width / imageWidth; double scaleY = (double) height / imageHeight; AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); BufferedImageOp op = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); return op.filter(image, new BufferedImage(width, height, image.getType())); }