BufferedImage bufferedImage=new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); //
Graphics graphics=bufferedImage.getGraphics();
Graphics graphics=bufferedImage.getGraphics();
String a="1234567890";
for(int i=0;i<4;i++) {
a+=String.valueOf(new Random().nextInt(10));
graphics.drawString(a,(12*i+12,16); }
graphics.dispose();
ImageIO.write(bufferedImage, "JPEG", response.getOutputStream());
运行如上代码得到如下图: