Generate JPEG image in jsp code : Image Creation « JSP « Java Tutorial






<%@ page contentType="image/jpeg" import="java.io.*, java.awt.*, java.awt.image.*,com.sun.image.codec.jpeg.*" %>
<%
    try {
        BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = image.createGraphics();
        g.drawLine(0, 0, 199, 199);

        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(response.getOutputStream());
        encoder.encode(image);

    } catch (Exception e) {}
%>








23.44.Image Creation
23.44.1.Generate JPEG image in jsp code
23.44.2.Use passed in parameter to draw a JPEG image
23.44.3.Return an Image From JSP Page