#if Java
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public static void DrawText(String input, String text1, String text2, int sts, int X, int Y, String output) throws Exception
{
BufferedImage img = null;
try {
img = ImageIO.read(new File(input));
}
catch (Exception e) {
throw new RuntimeException(e);
}
Graphics graphics = img.getGraphics();
if (sts == 2) {
graphics.setColor(Color.BLACK); }
else {
graphics.setColor(Color.WHITE);
}
// Get the FontMetrics
Font font = new Font("Arial", Font.BOLD, 40);
FontMetrics metrics = graphics.getFontMetrics(font);
// Determine the X coordinate for the text1
Rectangle rect = new Rectangle(0,0,img.getWidth(),img.getHeight());
int x = rect.x + (rect.width - metrics.stringWidth(text1)) / 2;
// Determine the Y coordinate for the text (note we add the ascent, as in java 2d 0 is top of the screen)
int y = rect.y + ((rect.height - metrics.getHeight()) / 4) + metrics.getAscent();
// Set the font
graphics.setFont(font);
graphics.drawString(text1, x, y);
int x2;
int y2;
if (!"^".equals(text2)) {
font = new Font("Arial", Font.BOLD, 32);
metrics = graphics.getFontMetrics(font);
// Determine the X coordinate for the text2
x2 = rect.x + (rect.width - metrics.stringWidth(text2)) / 2;
y2 = y + rect.y + ((rect.height - metrics.getHeight()) / 4) + 15;
graphics.setFont(font);
graphics.drawString(text2, x2, y2);
}
ImageIO.write(img, "png", new File(output));
}
#End If