2010-04-29 20 views

Respuesta

8

Sure. Primero cargue la imagen, probablemente usando un método de ImageIO. Luego, utilizando un objeto Graphics que representa la imagen en sí, llame al método drawString.

2

sí, java.awt.*

Here's un ejemplo; hay cientos por ahí.

26

Prueba el código de abajo

import java.awt.Color; 
import java.awt.Font; 
import java.awt.Graphics; 
import java.awt.image.BufferedImage; 
import java.io.File; 
import java.io.IOException; 
import javax.imageio.ImageIO; 

public class Testing { 
    public static void main(String arg[]) throws IOException { 
     String key = "Sample"; 
     BufferedImage bufferedImage = new BufferedImage(170, 30, 
       BufferedImage.TYPE_INT_RGB); 
     Graphics graphics = bufferedImage.getGraphics(); 
     graphics.setColor(Color.LIGHT_GRAY); 
     graphics.fillRect(0, 0, 200, 50); 
     graphics.setColor(Color.BLACK); 
     graphics.setFont(new Font("Arial Black", Font.BOLD, 20)); 
     graphics.drawString(key, 10, 25); 
     ImageIO.write(bufferedImage, "jpg", new File(
       "C:/Users/admin/desktop/image.jpg")); 
     System.out.println("Image Created"); 
    } 
} 
Cuestiones relacionadas