gpt4 book ai didi

java - 在Java中将文本写到图像上

转载 作者:太空狗 更新时间:2023-10-29 22:59:36 25 4
gpt4 key购买 nike

是否有Java 库可以将文本写入图像,与PHP 相同GD library .

最佳答案

试试下面的代码

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");
}
}

关于java - 在Java中将文本写到图像上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2736320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com