List of usage examples for java.awt.geom AffineTransform translate
public void translate(double tx, double ty)
From source file:BasicShapes.java
public static void main(String[] args) { AffineTransform tx = new AffineTransform(); tx.translate(1, 10); Rectangle shape = new Rectangle(1, 1, 1, 1); Shape newShape = tx.createTransformedShape(shape); }
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 = new AffineTransform(); tx.translate(2, 1); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); bufferedImage = op.filter(bufferedImage, null); }
From source file:Main.java
public static void main(String[] args) { AffineTransform tx = new AffineTransform(); tx.translate(1, 10); Rectangle shape = new Rectangle(1, 1, 1, 1); Shape newShape = tx.createTransformedShape(shape); System.out.println("done"); }
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(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[] 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:org.eclipse.swt.snippets.Snippet361.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 361"); shell.setText("Translate and Rotate an AWT Image in an SWT GUI"); shell.setLayout(new GridLayout(8, false)); Button fileButton = new Button(shell, SWT.PUSH); fileButton.setText("&Open Image File"); fileButton.addSelectionListener(widgetSelectedAdapter(e -> { String filename = new FileDialog(shell).open(); if (filename != null) { image = Toolkit.getDefaultToolkit().getImage(filename); canvas.repaint();// w w w. j a va2s. c o m } })); new Label(shell, SWT.NONE).setText("Translate &X by:"); final Combo translateXCombo = new Combo(shell, SWT.NONE); translateXCombo.setItems("0", "image width", "image height", "100", "200"); translateXCombo.select(0); translateXCombo.addModifyListener(e -> { translateX = numericValue(translateXCombo); canvas.repaint(); }); new Label(shell, SWT.NONE).setText("Translate &Y by:"); final Combo translateYCombo = new Combo(shell, SWT.NONE); translateYCombo.setItems("0", "image width", "image height", "100", "200"); translateYCombo.select(0); translateYCombo.addModifyListener(e -> { translateY = numericValue(translateYCombo); canvas.repaint(); }); new Label(shell, SWT.NONE).setText("&Rotate by:"); final Combo rotateCombo = new Combo(shell, SWT.NONE); rotateCombo.setItems("0", "Pi", "Pi/2", "Pi/4", "Pi/8"); rotateCombo.select(0); rotateCombo.addModifyListener(e -> { rotate = numericValue(rotateCombo); canvas.repaint(); }); Button printButton = new Button(shell, SWT.PUSH); printButton.setText("&Print Image"); printButton.addSelectionListener(widgetSelectedAdapter(e -> { performPrintAction(display, shell); })); composite = new Composite(shell, SWT.EMBEDDED | SWT.BORDER); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 8, 1); data.widthHint = 640; data.heightHint = 480; composite.setLayoutData(data); Frame frame = SWT_AWT.new_Frame(composite); canvas = new Canvas() { @Override public void paint(Graphics g) { if (image != null) { g.setColor(Color.WHITE); g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); /* Use Java2D here to modify the image as desired. */ Graphics2D g2d = (Graphics2D) g; AffineTransform t = new AffineTransform(); t.translate(translateX, translateY); t.rotate(rotate); g2d.setTransform(t); /*------------*/ g.drawImage(image, 0, 0, this); } } }; frame.add(canvas); composite.getAccessible().addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { e.result = "Image drawn in AWT Canvas"; } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Main.java
private static AffineTransform createRandomTransform(double angleRad) { AffineTransform at = new AffineTransform(); double scale = 1.0; at.translate(randomDouble(), randomDouble()); scale = Math.abs(randomDouble()); at.scale(scale, scale);/*from ww w . java2s . com*/ at.rotate(angleRad); at.translate(randomDouble(), randomDouble()); scale = Math.abs(randomDouble()); at.scale(scale, scale); return at; }
From source file:Main.java
private static BufferedImage renderRotatedObject(Object src, double angle, int width, int height, double tx, double ty) { BufferedImage dest = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = (Graphics2D) dest.getGraphics(); g2d.setColor(Color.black);// w ww. j a v a 2s . co m g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AffineTransform at = AffineTransform.getRotateInstance(angle); at.translate(tx, ty); g2d.setTransform(at); if (src instanceof TextLayout) { TextLayout tl = (TextLayout) src; tl.draw(g2d, 0, tl.getAscent()); } else if (src instanceof Image) { g2d.drawImage((Image) src, 0, 0, null); } g2d.dispose(); return dest; }
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); }