我正在使用 Prime-faces。这里我需要使用java将动态文本添加到图像底部。 即,我需要在图像上“书写”,并且需要将带有文本的图像保存在我想要的 PC 位置。
我试过这个:
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"));
}
如何实现?
您可以使用 Graphics 对象在 BufferedImage 上绘图:
Graphics2D g = (Graphics2D) image.getGraphics();
g.drawString("hello", x, y);
你有将txt文件插入图像的代码吗?
示例文件insert.txt内容
注意。 亚马逊野生动物