Example usage for java.awt.geom AffineTransform AffineTransform

List of usage examples for java.awt.geom AffineTransform AffineTransform

Introduction

In this page you can find the example usage for java.awt.geom AffineTransform AffineTransform.

Prototype

public AffineTransform() 

Source Link

Document

Constructs a new AffineTransform representing the Identity transformation.

Usage

From source file:org.nekorp.workflow.desktop.servicio.reporte.orden.servicio.OrdenServicioDataFactory.java

private void generaImagenDamage(ShapeView fondo, List<DamageDetailsVB> danios, File outputfile, int width,
        int height) {
    try {/*from w w w  . j  a  va2 s . c  o m*/
        Point contexto = new Point((width - fondo.getShapeWidth()) / 2, (height - fondo.getShapeHeight()) / 2);
        BufferedImage off_Image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = off_Image.createGraphics();
        g2.setColor(Color.WHITE);
        g2.fillRect(0, 0, width, height);
        AffineTransform saveXform = g2.getTransform();
        AffineTransform toCenterAt = new AffineTransform();
        toCenterAt.translate(contexto.getX(), contexto.getY());
        g2.transform(toCenterAt);
        fondo.paint(g2);
        g2.setTransform(saveXform);
        for (DamageDetailsVB x : danios) {
            DamageDetailGraphicsView obj = new DamageDetailGraphicsView();
            obj.setPosicion(new Point(x.getX(), x.getY()));
            obj.setContexto(contexto);
            if (x.getX() <= fondo.getShapeWidth() / 2) {
                if (x.getY() <= fondo.getShapeHeight() / 2) {
                    obj.setOrientacion(DamageDetailGraphicsView.SuperiorIzquierda);
                } else {
                    obj.setOrientacion(DamageDetailGraphicsView.InferiorIzquierda);
                }
            } else {
                if (x.getY() <= fondo.getShapeHeight() / 2) {
                    obj.setOrientacion(DamageDetailGraphicsView.SuperiorDerecha);
                } else {
                    obj.setOrientacion(DamageDetailGraphicsView.InferiorDerecha);
                }
            }
            obj.setCategoria(x.getCategoria());
            obj.setCaracteristica(x.getCaracteristica());
            obj.paint(g2);
        }
        saveJPG(off_Image, outputfile);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java

public void updateBackgroundImage(final ImageIcon icon, final int x, final int y) {
    if (paintableAssociatedToBackgroundImage != null)
        vv.removePreRenderPaintable(paintableAssociatedToBackgroundImage);
    paintableAssociatedToBackgroundImage = null;
    if (icon != null) {
        this.paintableAssociatedToBackgroundImage = new VisualizationViewer.Paintable() {
            public void paint(Graphics g) {
                Graphics2D g2d = (Graphics2D) g;
                AffineTransform oldXform = g2d.getTransform();
                AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer()
                        .getTransformer(Layer.LAYOUT).getTransform();
                AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer()
                        .getTransformer(Layer.VIEW).getTransform();
                AffineTransform at = new AffineTransform();
                at.concatenate(g2d.getTransform());
                at.concatenate(vat);//from www  . j a va2 s .  c o  m
                at.concatenate(lat);
                g2d.setTransform(at);
                g.drawImage(icon.getImage(), x, y, icon.getIconWidth(), icon.getIconHeight(), vv);
                g2d.setTransform(oldXform);
            }

            public boolean useTransform() {
                return false;
            }
        };
        vv.addPreRenderPaintable(paintableAssociatedToBackgroundImage);
    }
}

From source file:HelloUniverse.java

private void drawXPip(Graphics2D g2, float angle) {
    AffineTransform trans = new AffineTransform();
    int y;//from w  w  w  .jav  a2s  .  c  o m
    int xOrig = margin + diameter + space;
    int yOrig = margin;
    Color origColor = g2.getColor();

    if (angle <= Math.PI) {
        y = yOrig + diameter - (int) ((Math.abs(angle - Math.PI / 2) / (Math.PI / 2)) * diameter / 2);
    } else
        y = yOrig + (int) ((Math.abs((angle - Math.PI * 1.5)) / (Math.PI / 2)) * diameter / 2);

    if (angle < Math.PI / 2 || angle > Math.PI * 1.5)
        g2.setColor(Color.red); // Infront of wheel
    else {
        g2.setColor(Color.black); // Behind Wheel
        g2.setClip(xBackClip);
    }

    g2.setXORMode(getBackground());
    trans.setToTranslation(xOrig + pipOffset, y);
    g2.setTransform(trans);
    g2.fillPolygon(xPip);

    // Reset graphics context
    trans.setToIdentity();
    g2.setTransform(trans);
    g2.setColor(origColor);
    g2.setPaintMode();
}

From source file:net.sf.ginp.browser.FolderManagerImpl.java

void makeThumbImage(final File origPicture, final String thumbFileName, final int maxThumbSize) {
    if (log.isDebugEnabled()) {
        log.debug("makeThumbImage: origFileName=" + origPicture.getAbsolutePath() + " thumbFileName="
                + thumbFileName + " maxThumbSize=" + maxThumbSize);
    }/*from  ww w .ja  v a2s . c o  m*/

    // Only jpegs supported.
    if ((origPicture.getName().toLowerCase()).endsWith(".jpg")
            || (origPicture.getName().toLowerCase()).endsWith(".jpeg")) {
        try {
            // thumb it.
            JPEGImageDecoder dc = JPEGCodec.createJPEGDecoder((new FileInputStream(origPicture)));
            BufferedImage origImage = dc.decodeAsBufferedImage();
            int origHeight = origImage.getHeight(null);
            int origWidth = origImage.getWidth(null);
            int scaledW = 0;
            int scaledH = 0;
            double scale = 1.0;

            if (origHeight < origWidth) {
                scale = (double) maxThumbSize / (double) origWidth;
            } else {
                scale = (double) maxThumbSize / (double) origHeight;
            }

            scaledW = (int) (scale * origWidth);
            scaledH = (int) (scale * origHeight);

            //AffineTransform  at  = new AffineTransform();
            AffineTransform tx;
            AffineTransformOp af;
            JPEGImageEncoder encoder;
            BufferedImage outImage;

            outImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB);
            tx = new AffineTransform();
            tx.scale(scale, scale);
            af = new AffineTransformOp(tx, null);
            af.filter(origImage, outImage);

            File ginpFolder = new File(
                    thumbFileName.substring(0, thumbFileName.lastIndexOf("/.ginp")) + "/.ginp");

            if (!(ginpFolder.exists())) {
                ginpFolder.mkdir();
            }

            encoder = JPEGCodec.createJPEGEncoder(new FileOutputStream(thumbFileName));
            encoder.encode(outImage);
        } catch (Exception e) {
            log.error("Error Makeing Thumb Image " + thumbFileName, e);
        }
    }
}

From source file:HelloUniverse.java

private void drawYPip(Graphics2D g2, float angle) {
    AffineTransform trans = new AffineTransform();
    int x;/*  w  ww. j av a  2s. c  om*/
    int xOrig = margin;
    int yOrig = margin + diameter + space;
    Color origColor = g2.getColor();

    if (angle <= Math.PI) {
        x = xOrig + diameter - (int) ((Math.abs(angle - Math.PI / 2) / (Math.PI / 2)) * diameter / 2);
    } else
        x = xOrig + (int) ((Math.abs((angle - Math.PI * 1.5)) / (Math.PI / 2)) * diameter / 2);

    if (angle < Math.PI / 2 || angle > Math.PI * 1.5)
        g2.setColor(Color.red); // Infront on wheel
    else {
        g2.setColor(Color.black); // Behind Wheel
        g2.setClip(yBackClip);
    }

    g2.setXORMode(getBackground());
    trans.setToTranslation(x, yOrig + pipOffset);
    g2.setTransform(trans);
    g2.fillPolygon(yPip);

    // Reset graphics context
    trans.setToIdentity();
    g2.setTransform(trans);
    g2.setColor(origColor);
    g2.setPaintMode();
}

From source file:org.apache.fop.afp.AFPGraphics2D.java

/** {@inheritDoc} */
@Override/*from   w w  w  . ja va 2s  .c  o  m*/
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
    // draw with AWT Graphics2D
    Dimension imageSize = new Dimension(width, height);
    BufferedImage bufferedImage = buildBufferedImage(imageSize);

    boolean drawn = drawBufferedImage(img, bufferedImage, width, height, observer);
    if (drawn) {
        drawRenderedImage(bufferedImage, new AffineTransform());
    }
    return false;
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static BufferedImage rotateImage(BufferedImage img, double angle, int type, Color fillBgColor) {
    if (img == null) {
        return null;
    }/*from  ww  w  . j  ava2s  . c om*/

    if (angle > 360.0 || angle < -360) {
        angle = angle % 360.0;
    }

    if (angle < 0) {
        angle = 360 + angle;
    }

    if (angle == 0.0 || angle == 360.0) {
        return img;
    }

    //System.out.println("angle="+angle);

    int w = img.getWidth();
    int h = img.getHeight();

    /*
    AffineTransform tr = new AffineTransform();
    tr.rotate(theta,w/2,h/2);
    BufferedImageOp op = new AffineTransformOp(tr, type);
    BufferedImage out = op.filter(img,null);
     */
    /*
    AffineTransform tr = new AffineTransform();
    tr.rotate(theta, w/2.0, h/2.0);
    AffineTransform translationTransform = findTranslation(tr, img);
    tr.preConcatenate(translationTransform);
    BufferedImageOp op = new AffineTransformOp(tr, type);
            
    BufferedImage out = op.filter(img,null);
     */
    BufferedImage out = null;
    if (angle == 90.0 || angle == 180.0 || angle == 270.0) {
        switch ((int) angle) {
        case 90:
            out = new BufferedImage(h, w, img.getType());
            for (int x = 0; x < w; x++) {
                for (int y = 0; y < h; y++) {
                    out.setRGB(h - y - 1, x, img.getRGB(x, y));
                }
            }
            break;
        case 180:
            out = new BufferedImage(w, h, img.getType());
            for (int x = 0; x < w; x++) {
                for (int y = 0; y < h; y++) {
                    out.setRGB(w - x - 1, h - y - 1, img.getRGB(x, y));
                }
            }
            break;
        case 270:
            out = new BufferedImage(h, w, img.getType());
            for (int x = 0; x < w; x++) {
                for (int y = 0; y < h; y++) {
                    out.setRGB(y, w - x - 1, img.getRGB(x, y));
                }
            }
            break;
        }
    } else {
        double theta = angle * Math.PI / 180.0;
        int neww = w, newh = h;
        double dx = 0.0, dy = 0.0;
        double s = Math.sin(theta);
        double c = Math.cos(theta);
        if (angle > 0.0 && angle < 90.0) {
            neww = (int) Math.round(((double) w) * c + ((double) h) * s);
            newh = (int) Math.round(((double) w) * s + ((double) h) * c);
            dx = ((double) h) * s;
            dy = 0.0;
        } else if (angle > 90.0 && angle < 180.0) {
            neww = (int) Math.round(-((double) w) * c + ((double) h) * s);
            newh = (int) Math.round(((double) w) * s - ((double) h) * c);
            dx = -((double) w) * c + ((double) h) * s;
            dy = -((double) h) * c;
        } else if (angle > 180.0 && angle < 270.0) {
            neww = (int) Math.round(-((double) w) * c - ((double) h) * s);
            newh = (int) Math.round(-((double) w) * s - ((double) h) * c);
            dx = -((double) w) * c;
            dy = -((double) w) * s - ((double) h) * c;
        } else if (angle > 270.0 && angle < 360.0) {
            neww = (int) Math.round(((double) w) * c - ((double) h) * s);
            newh = (int) Math.round(-((double) w) * s + ((double) h) * c);
            dx = 0.0;
            dy = -((double) w) * s;
        }

        AffineTransform tr = new AffineTransform();
        tr.translate(dx, dy);
        tr.rotate(theta);
        BufferedImageOp op = new AffineTransformOp(tr, type);
        out = new BufferedImage(neww, newh, img.getType());
        Graphics2D g2d = (Graphics2D) out.getGraphics();
        Rectangle clear = new Rectangle(0, 0, out.getWidth(), out.getHeight());
        g2d.setPaint(fillBgColor);
        g2d.fill(clear);
        op.filter(img, out);
    }
    return out;
}

From source file:HelloUniverse.java

private void drawZPip(Graphics2D g2, float zAngle) {
    AffineTransform trans = new AffineTransform();
    Color origColor = g2.getColor();

    trans.translate(margin, margin);//  w  w w . j  a va2s.co m
    trans.rotate(zAngle, diameter / 2, diameter / 2);

    g2.setXORMode(getBackground());
    g2.setTransform(trans);
    g2.setColor(Color.red);
    g2.fillPolygon(zPip);

    // Reset graphics context
    trans.setToIdentity();
    g2.setTransform(trans);
    g2.setColor(origColor);
    g2.setPaintMode();
}

From source file:com.aimluck.eip.fileupload.util.FileuploadUtils.java

public static AffineTransform getExifTransformation(ImageInformation info) {

    AffineTransform t = new AffineTransform();
    if (info == null) {
        return t;
    }//ww  w  .  j a v a 2s  . co m

    switch (info.orientation) {
    case 1:
        break;
    case 2: // Flip X
        t.scale(-1.0, 1.0);
        t.translate(-info.width, 0);
        break;
    case 3: // PI rotation
        t.translate(info.width, info.height);
        t.rotate(Math.PI);
        break;
    case 4: // Flip Y
        t.scale(1.0, -1.0);
        t.translate(0, -info.height);
        break;
    case 5: // - PI/2 and Flip X
        t.rotate(-Math.PI / 2);
        t.scale(-1.0, 1.0);
        break;
    case 6: // -PI/2 and -width
        t.translate(info.height, 0);
        t.rotate(Math.PI / 2);
        break;
    case 7: // PI/2 and Flip
        t.scale(-1.0, 1.0);
        t.translate(-info.height, 0);
        t.translate(0, info.width);
        t.rotate(3 * Math.PI / 2);
        break;
    case 8: // PI / 2
        t.translate(0, info.width);
        t.rotate(3 * Math.PI / 2);
        break;
    default:
        break;
    }

    return t;
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java

private static Shape createShape(double x, double y, Rectangle2D hotspot) {
    Area result = new Area(new RoundRectangle2D.Double(hotspot.getX(), hotspot.getY(), hotspot.getWidth(),
            hotspot.getHeight(), 8, 8));

    boolean right = hotspot.getMinX() > x;

    Polygon po = new Polygon();
    po.addPoint(0, 0);/*from   www. ja  va  2  s.c o m*/
    po.addPoint(0, 10);
    po.addPoint(10, 0);
    AffineTransform af = new AffineTransform();
    if (right) {
        af.translate(hotspot.getX() - 7, hotspot.getY() + hotspot.getHeight() / 2);
        af.rotate(-Math.PI / 4);
    } else {
        af.translate(hotspot.getMaxX() + 7, hotspot.getY() + hotspot.getHeight() / 2);
        af.rotate(Math.PI * 3 / 4);
    }

    Shape shape = af.createTransformedShape(po);
    result.add(new Area(shape));
    return result;
}