参考了相关程序,希望对大家的学习有所帮助!
<%@ page language="java" contentType="image/png;charset=GB2312"
import="java.awt.image.*"
import="java.awt.*"
import="javax.imageio.*"
import="java.io.*"
import="java.net.URL"
%>
<%
response.reset();// 清空缓冲区
response.setContentType("image/png");// 注意这里的MIME类型
int width = 640, height = 480; // 创建一个 640X480 的图像
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
// 填充背景
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
g.setColor(Color.BLACK);
// 设置标题
g.setFont(new Font("汉真广标", Font.PLAIN, 35));
Image logoBMP;
// 加载并显示图像
String ss="http://www.zp123.com/pic/tese/gamemm/830/20041105025718(3).jpg";
logoBMP = ImageIO.read(new URL(ss));
g.drawImage(logoBMP, 10, 50, null);
g.drawString("一张美女图片", 30, 100);
// 部署图形
g.dispose();
// 利用ImageIO类的write方法对图像进行编码
ServletOutputStream sos = response.getOutputStream();
ImageIO.write(image, "PNG", sos);
sos.flush();
sos.close();
//response.reset();
%>