Reputation: 902
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?
Upvotes: 1
Views: 5573
Reputation: 1
you have code for insert txt file to images?
sample file insert.txt content
Note. Wildlife of Amazon
Upvotes: 0
Reputation: 111359
You can draw on a BufferedImage using the the Graphics object:
Graphics2D g = (Graphics2D) image.getGraphics();
g.drawString("hello", x, y);
Upvotes: 0