验证码无法显示 java_验证码不能显示

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

我设了下断点 是在

BufferedImage img = new BufferedImage(imageData.getWidth(),

这边的时候出错,请问是什么原因。

public void paint(OutputStream out, Object data) throws IOException {

ImageData imageData = (ImageData) data;

// 生成一个在1000-9999之间的随机数

Random randomNumber = new Random();

String keyCode = randomNumber.nextInt(8999) + 1000 + "";

//把产生的随机数保存到session中

System.out.println(keyCode);

HttpSession session = (HttpSession)FacesContext.getCurrentInstance()

.getExternalContext().getSession(true);

session.setAttribute("keyCode", keyCode);

//生成干扰线的随机数

int outPutLine = 0;

outPutLine = randomNumber.nextInt(100);

BufferedImage img = new BufferedImage(imageData.getWidth(),

imageData.getHeight(), BufferedImage.TYPE_INT_RGB);

Graphics2D g = img.createGraphics();

g.setBackground(imageData.getBackground());

g.setColor(imageData.getDrawColor());

g.setFont(imageData.getTextFont());

//画矩形

g.clearRect(0, 0, imageData.getWidth(), imageData.getHeight());

//画干扰线

g.drawLine(outPutLine, outPutLine, imageData.getWidth()

- outPutLine, imageData.getHeight() - outPutLine);

//画产生的随机数

g.drawString(keyCode, 10, 16);

g.dispose();

ImageIO.write(img, "jpeg", out);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值