Example usage for java.awt.geom AffineTransform getScaleInstance

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

Introduction

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

Prototype

public static AffineTransform getScaleInstance(double sx, double sy) 

Source Link

Document

Returns a transform representing a scaling transformation.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED);

    AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
    tx.translate(-bufferedImage.getWidth(null), 0);
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    bufferedImage = op.filter(bufferedImage, null);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED);

    AffineTransform tx = AffineTransform.getScaleInstance(-1, -1);
    tx.translate(-bufferedImage.getWidth(null), -bufferedImage.getHeight(null));
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    bufferedImage = op.filter(bufferedImage, null);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED);

    AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
    tx.translate(0, -bufferedImage.getHeight(null));
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    bufferedImage = op.filter(bufferedImage, null);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage bsrc = ImageIO.read(new File("a.jpg"));
    BufferedImage bdest = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bdest.createGraphics();
    AffineTransform at = AffineTransform.getScaleInstance(2, 2);
    g.drawRenderedImage(bsrc, at);/*from  w ww.  j  a  v a2s  .c om*/
    ImageIO.write(bdest, "JPG", new File("b.jpg"));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage bufferedImage = ImageIO.read(new File("a.jpg"));
    BufferedImage destinationBufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = destinationBufferedImage.createGraphics();
    AffineTransform at = AffineTransform.getScaleInstance(2, 2);
    g.drawRenderedImage(bufferedImage, at);
    ImageIO.write(destinationBufferedImage, "JPG", new File("b.jpg"));
}

From source file:AffineTransformationPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {/*from  w  w w  .  j  a  v  a2 s.co m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AffineTransformationPDF.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        cb.transform(AffineTransform.getScaleInstance(1.2, 0.75));

        cb.moveTo(216, 720);
        cb.lineTo(360, 360);
        cb.lineTo(360, 504);
        cb.lineTo(72, 144);
        cb.lineTo(144, 288);
        cb.stroke();

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:Main.java

public static BufferedImage getFlippedImage(BufferedImage bi) {
    BufferedImage flipped = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType());
    AffineTransform tran = AffineTransform.getTranslateInstance(0, bi.getHeight());
    AffineTransform flip = AffineTransform.getScaleInstance(1d, -1d);
    tran.concatenate(flip);/*from  w ww.j av  a  2s .  co m*/

    Graphics2D g = flipped.createGraphics();
    g.setTransform(tran);
    g.drawImage(bi, 0, 0, null);
    g.dispose();

    return flipped;
}

From source file:AffineTransformGetScaleInstance.java

public void paint(Graphics g) {
    AffineTransform atrans = null;

    Graphics2D g2d = (Graphics2D) g;
    atrans = AffineTransform.getScaleInstance(2, 3);

    if (atrans != null)
        g2d.setTransform(atrans);/*from  w w w . j ava 2  s  .com*/

    g2d.fillRect(50, 50, 100, 50);
}

From source file:ImageFlip.java

public void paint(Graphics g) {
    Image myImage = new ImageIcon("yourImage.jpg").getImage();
    BufferedImage bufferedImage = new BufferedImage(myImage.getWidth(null), myImage.getHeight(null),
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) g;

    Graphics gb = bufferedImage.getGraphics();
    gb.drawImage(myImage, 0, 0, null);// w  w  w.  j  a va2  s  .c  om
    gb.dispose();

    AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
    tx.translate(-myImage.getWidth(null), 0);
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    bufferedImage = op.filter(bufferedImage, null);

    g2d.drawImage(myImage, 10, 10, null);
    g2d.drawImage(bufferedImage, null, 300, 10);
}

From source file:de.mfo.jsurf.Main.java

public static BufferedImage flipV(BufferedImage bi) {
    AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
    tx.translate(0, -bi.getHeight(null));
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    return op.filter(bi, null);
}