java web 图片显示
response.setContentType("image/jpeg");
String img = request.getParameter("img");
String filePath = request.getServletContext().getRealPath("/upload/")+img;
BufferedImage out = ImageIO.read(new File(filePath));
ServletOutputStream outputStream = response.getOutputStream();
ImageIO.write(out, "png", outputStream);
java web 创建图片
response.setContentType("image/png");
BufferedImage img = new BufferedImage(100,38, BufferedImage.TYPE_INT_RGB);
Graphics g = img.getGraphics();
g.setColor(new Color(69,195,241));
g.fillRect(0,0,100,38);
g.setColor(Color.white);
Font font = new Font("",Font.PLAIN,23);
g.setFont(font);
String session = UUID.randomUUID().toString().replaceAll("-","").substring(3,7);
g.drawString(session,15,28);
g.drawLine(new Random().nextInt(92), new Random().nextInt(40), new Random().nextInt(92), new Random().nextInt(40));
g.drawLine(new Random().nextInt(92), new Random().nextInt(40), new Random().nextInt(92), new Random().nextInt(40));
g.drawLine(new Random().nextInt(92), new Random().nextInt(40), new Random().nextInt(92), new Random().nextInt(40));
g.drawLine(new Random().nextInt(92), new Random().nextInt(40), new Random().nextInt(92), new Random().nextInt(40));
g.drawLine(new Random().nextInt(92), new Random().nextInt(40), new Random().nextInt(92), new Random().nextInt(40));
g.drawLine(new Random().nextInt(92), new Random().nextInt(40), new Random().nextInt(92), new Random().nextInt(40));
g.drawLine(new Random().nextInt(92), new Random().nextInt(40), new Random().nextInt(92), new Random().nextInt(40));
g.dispose();
request.getSession().setAttribute("validation",session);
ImageIO.write(img, "png", response.getOutputStream());