print JavaFX Mirror Image - Java JavaFX

Java examples for JavaFX:Image

Description

print JavaFX Mirror Image

Demo Code


//package com.java2s;

import java.awt.Color;

import java.awt.Graphics2D;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;

import javafx.embed.swing.SwingFXUtils;

import javafx.scene.image.Image;
import javafx.scene.image.WritableImage;

public class Main {
    public static Image printMirrorImage(String str, int size, Color color) {
        BufferedImage bufferedImage = new BufferedImage(70, 50,
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = bufferedImage.createGraphics();
        g2d.setFont(new java.awt.Font("Sans Serif", java.awt.Font.BOLD,
                size));/*from   ww w. j  a va  2  s  . co m*/
        g2d.setColor(color);
        g2d.drawString(str, 10, 10);
        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);
        WritableImage wr = null;
        Image img = SwingFXUtils.toFXImage(bufferedImage, wr);
        return img;
    }
}

Related Tutorials