Wu Yuxiong--Natural JAVA development JSP-Servlet study notes: response object-server response to the client

<%-- 
    Document   : img
    Created on : 2020-4-12, 7:49:34
    Author     : Administrator
--%>

<%@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; charset=UTF-8">
        <title > JSP Page </ title > 
    </ head > 
    < body > 
        <% 
// Create BufferedImage object 
            BufferedImage image =  new BufferedImage ( 340 , 160 , BufferedImage.TYPE_INT_RGB);
 // Get Graphics object 
            Graphics g = image with Image object . getGraphics ();
 // Drawing with Graphics, the drawn image will appear in the image object 
            g.fillRect ( 0 , 0 , 400 , 400 );
 // Set the color: red
            g.setColor (new Color ( 255 , 0 , 0 ));
 // Draw an arc 
            g.fillArc ( 20 , 20 , 100 , 100 , 30 , 120 );
 // Set the color: green 
            g.setColor ( new Color ( 0 , 255 , 0 ));
 // Draw an arc 
            g.fillArc ( 20 , 20 , 100 , 100 , 150 , 120 );
 // Set the color: blue 
            g.setColor ( new Color ( 0 , 0 , 255 ));
 // Draw an arc 
            g.fillArc ( 20 , 20 , 100 , 100 , 270 , 120 );
 // Set the color : Black 
            g.setColor ( new Color ( 0 , 0 , 0 )); 
            g.setFont ( new Font ( " Arial Black " , Font.PLAIN, 16 ));
//  Draw three strings
            g.drawString ( " red: climb " , 200 , 60 ); 
            g.drawString ( " green: swim " , 200 , 100 ); 
            g.drawString ( " blue: jump " , 200 , 140 ); 
            g.dispose (); 
// Response to output the image to the page 
            ImageIO.write (image, " png " , response.getOutputStream ());
         %> 
    </ body > 
</ html >

 

Guess you like

Origin www.cnblogs.com/tszr/p/12683609.html