jsp中如何将文字添加在已经存在的图片
JSP给图片添加文字
70 && height>30){
//创建一个BufferedImage来作为图像操作容器
BufferedImage image = new BufferedImage(width, height, BufferedImage。 TYPE_INT_RGB);
//创建一个绘图环境来进行绘制图象
Graphics g = image。getGraphics();
//将原图像数据流载入这个BufferedImage
g。 drawImage(src,0,0,width,height,null);
//设定文本字体
g。setFont(new Font("宋体",...全部
JSP给图片添加文字
70 && height>30){
//创建一个BufferedImage来作为图像操作容器
BufferedImage image = new BufferedImage(width, height, BufferedImage。
TYPE_INT_RGB);
//创建一个绘图环境来进行绘制图象
Graphics g = image。getGraphics();
//将原图像数据流载入这个BufferedImage
g。
drawImage(src,0,0,width,height,null);
//设定文本字体
g。setFont(new Font("宋体",Font。PLAIN,48));
//设定文本
String rand = "中国";
//设定文本颜色
g。
setColor(Color。black);
//向BufferedImage写入文本字符
g。drawString(rand,20,50);
//使更改生效
g。
dispose();
//创建输出文件流
FileOutputStream outi = new FileOutputStream(OutFileName);
//创建JPEG编码对象
JPEGImageEncoder encodera = JPEGCodec。
createJPEGEncoder(outi);
//对这个BufferedImage (image)进行JPEG编码
encodera。encode(image);
outi。
close(); //关闭输出文件流
}
%>。收起