<% - Documento: img Creado en : 2020 - 4 - 12 , 7 : 49 : 34 Autor: Administrador - %> <% @page import = " javax.imageio.ImageIO " %> <% @page import = " java.awt.Font " %> <% @page import = " java.awt.Color " %> <% @page import = " java.awt.Graphics "%> <% @page import = " java.awt.image.BufferedImage " %> <% - 通过 contentType 属性 指定 响应 数据 是 图片- %> <% @page contentType = " image / png " language = " java " pageEncoding = " UTF-8 " %> <! DOCTYPE html > < html > < head > < meta http-equiv = "Content-Type" content = "text / html; title > Página JSP </ title > </ head > < body > <% // Crear objeto BufferedImage imagen BufferedImage = new BufferedImage ( 340 , 160 , BufferedImage.TYPE_INT_RGB); // Obtener objeto gráfico Graphics g = imagen con objeto Image . getGraphics (); // Dibujando con gráficos, la imagen dibujada aparecerá en el objeto de imagen g.fillRect ( 0 , 0 , 400 , 400 ); // Establezca el color: rojo g.setColor ( nuevo Color ( 255 , 0 , 0 )); // Dibuja un arco g.fillArc ( 20 , 20 , 100 , 100 , 30 , 120 ); // Establece el color: verde g.setColor ( nuevo Color ( 0 , 255 , 0 )); // Dibuja un arco g.fillArc ( 20 , 20 , 100 , 100 , 150 , 120 ); //Establecer color: azul g.setColor ( nuevo Color ( 0 , 0 , 255 )); // Dibujar un arco g.fillArc ( 20 , 20 , 100 , 100 , 270 , 120 ); // Establecer color: negro g. setColor ( new Color ( 0 , 0 , 0 )); g.setFont ( new Font ( " Arial Black " , Font.PLAIN, 16 )); Dibuja tres cadenas// g.drawString ( " rojo: subir " , 200 , 60 ); g.drawString ( " verde: nadar " , 200 , 100 ); g.drawString ( " azul: saltar " , 200 , 140 ); g.dispose (); // Respuesta para enviar la imagen a la página ImageIO.write (image, " png " , response.getOutputStream ()); %> </ body > </ html >