flip JavaFX Canvas Drawing - Java JavaFX

Java examples for JavaFX:Canvas

Description

flip JavaFX Canvas Drawing

Demo Code


import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.util.Objects;
import javafx.application.Platform;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.effect.Light.Point;
import javafx.scene.image.Image;
import javafx.scene.image.WritableImage;

public class Main{
    public static void flipCanvasDrawing(Canvas canvas, FLIP flip) {
        if (flip.equals(FLIP.R2L)) {
            canvas.getGraphicsContext2D().save();
            //         canvas.setTranslateY(0);
            canvas.setScaleX(-1);//from   w  w  w. j  a v  a 2s . c o  m
            canvas.setScaleY(1);
            canvas.getGraphicsContext2D().restore();
        } else {
            canvas.getGraphicsContext2D().save();
            //         canvas.setTranslateY(1);
            canvas.setScaleX(1);
            canvas.setScaleY(1);
            canvas.getGraphicsContext2D().restore();
        }
    }
}

Related Tutorials