Package com.benkyou.util

Source Code of com.benkyou.util.TextImageGenerator

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.benkyou.util;

import com.benkyou.client.systems.ImagingSystem;
import com.jme3.texture.Image;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Transparency;
import java.awt.geom.AffineTransform;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
import jme3tools.converters.ImageToAwt;

/**
*
* @author student
*/
public class TextImageGenerator {
    private BufferedImage bi;
    private String text;
    private Graphics2D g2d;
    public TextImageGenerator(String text){
        this.text = text;
        bi = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB);
        g2d = (Graphics2D) bi.getGraphics();
    }
    public Image getTextImage(){
        Font f = new Font("Dialog", Font.PLAIN, 100);
        g2d.setFont(f);
        g2d.drawString(text, 10f, 350f);
        AffineTransform tx = new AffineTransform();
       
        tx = AffineTransform.getScaleInstance(-1, 1);
        tx.translate(-bi.getWidth(null), 0);
       
        tx.rotate(Math.PI, bi.getWidth()/2, bi.getHeight()/2);
       
        AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
        bi = op.filter(bi, null);
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect((bi.getHeight() * bi.getWidth() * 4))
        byteBuffer.clear();
        ImageToAwt.convert(bi, ImagingSystem.jmeformat, byteBuffer);
        Image im = new Image(ImagingSystem.jmeformat, bi.getWidth(), bi.getHeight(), byteBuffer.duplicate(), null);
        return im;
    }
   
}
TOP

Related Classes of com.benkyou.util.TextImageGenerator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.