Here you can find the source of drawStringOnImage(Image image, String string, int x, int y)
public static Image drawStringOnImage(Image image, String string, int x, int y)
//package com.java2s; //License from project: Open Source License import java.awt.*; import java.awt.image.*; public class Main { public static Image drawStringOnImage(Image image, String string, int x, int y) { BufferedImage image1 = toBufferedImage(image); Graphics2D g = image1.createGraphics(); g.drawString(string, x, y);// w w w. j a v a 2s.c om return image1; } public static BufferedImage toBufferedImage(Image img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D bGr = bimage.createGraphics(); bGr.drawImage(img, 0, 0, null); bGr.dispose(); return bimage; } }