DS's『 행복합시다 』

Carpe Programming/jsp & spring & jstl

이미지 그리기

nolite 2014. 6. 30. 22:55

<%@ page contentType="text/html;charset=utf-8"%>

<%@ page import="java.awt.Graphics"%>

<%@ page import="java.awt.Color"%>

<%@ page import="java.awt.Font"%>

<%@ page import="java.awt.image.BufferedImage"%>

<%@ page import="java.io.BufferedInputStream"%>

<%@ page import="java.io.File"%>

<%@ page import="javax.imageio.ImageIO"%>

<%@ page import="java.io.InputStream"%>

<%@ page import="java.awt.Graphics2D"%>

<%@ page import="java.awt.Image"%>

<%@ page import="java.net.URL"%>

<%@ page import="java.sql.*"%>

<%@ page import="java.sql.*"%>

<%@ page import="java.io.OutputStream"%>

<%@ page import="java.util.Hashtable"%>

<%@ page import="java.util.ArrayList"%>

<%@ page import="java.text.SimpleDateFormat"%>

<%@ page import="java.util.Calendar"%>

<%@ include file="database.jsp"%>

<%

request.setCharacterEncoding("utf-8");

response.setContentType("text/html;charset=utf-8");


out.clear();

out = pageContext.pushBody();


OutputStream os = response.getOutputStream();

int width = 400, height = 300;

Font font = new Font("Monospaced", Font.PLAIN, 11);


try {

BufferedImage buffer_image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

Graphics g = buffer_image.getGraphics();


g.setFont(font);

g.setColor(new Color(255, 255, 255));

g.fillRect(0, 0, width, height);


g.setFont(new Font("Monospaced", Font.PLAIN, 35));

g.setColor(new Color(0, 0, 255));

g.drawString("K7", width/2, height/2);

ImageIO.write(buffer_image, "png", os);

//ImageIO.write(buffer_image, "png", new File("C:\\image_test.png"));

os.close();


} catch (Exception e) {

out.println(e.getMessage());

} finally {

}

 

%>

728x90