Как добавить текст к изображению в Java? ⇐ JAVA
-
Гость
Как добавить текст к изображению в Java?
I am using Prime-faces. Here i need to add dynamic text to bottom of the image using java. i.e, I need to "write" on the image and I need to save image with text in my desired PC location.
I have tried this:
public void writeToImage() throws MalformedURLException, IOException { final BufferedImage image = ImageIO.read(new URL( "http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png")); Graphics g = image.getGraphics(); g.setFont(g.getFont().deriveFont(30f)); g.drawString("Hello World!", 100, 100); g.dispose(); ImageIO.write(image, "png", new File("test.png")); } How do I achieve it?
Источник: https://stackoverflow.com/questions/177 ... ge-in-java
I am using Prime-faces. Here i need to add dynamic text to bottom of the image using java. i.e, I need to "write" on the image and I need to save image with text in my desired PC location.
I have tried this:
public void writeToImage() throws MalformedURLException, IOException { final BufferedImage image = ImageIO.read(new URL( "http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png")); Graphics g = image.getGraphics(); g.setFont(g.getFont().deriveFont(30f)); g.drawString("Hello World!", 100, 100); g.dispose(); ImageIO.write(image, "png", new File("test.png")); } How do I achieve it?
Источник: https://stackoverflow.com/questions/177 ... ge-in-java