이미지 생성 (이미지에 글자 입력)
------------------------------------------------------------------------------------
<%@ page
import = "com.mgame.mgcrypt"
import = "java.io.*"
import = "java.awt.*"
import = "java.awt.image.*"
import = "java.util.Random"
import = "javax.imageio.*"
%><%
mgcrypt obj = new mgcrypt();
String txt = "";
try {
txt = (request.getParameter("viewString")).trim();
txt = (obj.setDecrypt(txt, 2000)).trim();
} catch(NullPointerException e) {
}
// 이미지 생성
int w = 202, h = 73;
BufferedImage image = new BufferedImage( w, h, BufferedImage.TYPE_INT_RGB );
Graphics2D g2 = image.createGraphics();
// 스트로크 생성
BasicStroke stoke1 = new BasicStroke(1.0f);
BasicStroke stoke2 = new BasicStroke(2.0f);
BasicStroke stoke3 = new BasicStroke(3.0f);
// 배경 생성
int inc = 205;
int x = 0;
for(int i=0;i<50;i++) {
g2.setColor( new Color(inc+i,inc+i,inc+i) );
g2.fillRect( x, 0, x+4, h );
x += 4;
}
// 라인 생성
Random r = new Random();
g2.setColor( Color.lightGray );
int x1 = r.nextInt(197)+5;
int y1 = r.nextInt(68)+5;
for(int i=0;i<5;i++) {
int x2 = r.nextInt(197)+5;
int y2 = r.nextInt(68)+5;
int st = r.nextInt(4)+1;
if(st == 1) {
g2.setStroke(stoke3);
} else if(st == 2) {
g2.setStroke(stoke2);
} else {
g2.setStroke(stoke1);
}
g2.drawLine( x1, y1, x2, y2 );
x1 = x2; y1 = y2;
}
// 박스 생성
g2.setStroke(stoke2);
g2.setColor( Color.black );
g2.drawRect( 1, 1, w-2, h-2 );
// 텍스트 생성 - 1:+, 2:-, 3:>, 4:< (부등호는 무조건 왼쪽이 답)
String img_txt = "";
if(!txt.equals("") && txt != null) {
String temp_txt1 = "";
String temp_txt2 = txt.substring(4, 5);
if(temp_txt2.equals("1")) {
temp_txt1 = "과 ";
temp_txt2 = "를 더한 수는?";
} else if(temp_txt2.equals("2")) {
temp_txt1 = "에서 ";
temp_txt2 = "를 뺀 수는?";
} else if(temp_txt2.equals("3")) {
temp_txt1 = "과 ";
temp_txt2 = "중 큰 수는?";
} else if(temp_txt2.equals("4")) {
temp_txt1 = "과 ";
temp_txt2 = "중 작은 수는?";
} else {
temp_txt2 = "Error";
}
if(!temp_txt1.equals("")) {
img_txt = txt.substring(0, 2) + temp_txt1 + txt.substring(2, 4) + temp_txt2;
img_txt = new String(img_txt.getBytes("8859_1"),"euc-kr");
} else {
img_txt = temp_txt2;
}
}
// BatangChe, DotumChe, GulimChe, GungsuhChe, Serif, SansSerif, Monospaced, Dialog, Dialog Input
g2.setColor( Color.black );
g2.setFont(new Font("DotumChe",Font.BOLD,17));
g2.drawString(img_txt, 8, 44 );
// png 가 훨 깨끗함.
response.setContentType("image/png"); // jpg 로 바꿀때 image/png -> image/jpeg
OutputStream dest = response.getOutputStream();
ImageIO.write( image, "png", dest ); // jpg 로 바꿀때 png -> jpg
dest.flush();
dest.close();
%>
------------------------------------------------------------------------------------
<%@ page
import = "com.mgame.mgcrypt"
import = "java.io.*"
import = "java.awt.*"
import = "java.awt.image.*"
import = "java.util.Random"
import = "javax.imageio.*"
%><%
mgcrypt obj = new mgcrypt();
String txt = "";
try {
txt = (request.getParameter("viewString")).trim();
txt = (obj.setDecrypt(txt, 2000)).trim();
} catch(NullPointerException e) {
}
// 이미지 생성
int w = 202, h = 73;
BufferedImage image = new BufferedImage( w, h, BufferedImage.TYPE_INT_RGB );
Graphics2D g2 = image.createGraphics();
// 스트로크 생성
BasicStroke stoke1 = new BasicStroke(1.0f);
BasicStroke stoke2 = new BasicStroke(2.0f);
BasicStroke stoke3 = new BasicStroke(3.0f);
// 배경 생성
int inc = 205;
int x = 0;
for(int i=0;i<50;i++) {
g2.setColor( new Color(inc+i,inc+i,inc+i) );
g2.fillRect( x, 0, x+4, h );
x += 4;
}
// 라인 생성
Random r = new Random();
g2.setColor( Color.lightGray );
int x1 = r.nextInt(197)+5;
int y1 = r.nextInt(68)+5;
for(int i=0;i<5;i++) {
int x2 = r.nextInt(197)+5;
int y2 = r.nextInt(68)+5;
int st = r.nextInt(4)+1;
if(st == 1) {
g2.setStroke(stoke3);
} else if(st == 2) {
g2.setStroke(stoke2);
} else {
g2.setStroke(stoke1);
}
g2.drawLine( x1, y1, x2, y2 );
x1 = x2; y1 = y2;
}
// 박스 생성
g2.setStroke(stoke2);
g2.setColor( Color.black );
g2.drawRect( 1, 1, w-2, h-2 );
// 텍스트 생성 - 1:+, 2:-, 3:>, 4:< (부등호는 무조건 왼쪽이 답)
String img_txt = "";
if(!txt.equals("") && txt != null) {
String temp_txt1 = "";
String temp_txt2 = txt.substring(4, 5);
if(temp_txt2.equals("1")) {
temp_txt1 = "과 ";
temp_txt2 = "를 더한 수는?";
} else if(temp_txt2.equals("2")) {
temp_txt1 = "에서 ";
temp_txt2 = "를 뺀 수는?";
} else if(temp_txt2.equals("3")) {
temp_txt1 = "과 ";
temp_txt2 = "중 큰 수는?";
} else if(temp_txt2.equals("4")) {
temp_txt1 = "과 ";
temp_txt2 = "중 작은 수는?";
} else {
temp_txt2 = "Error";
}
if(!temp_txt1.equals("")) {
img_txt = txt.substring(0, 2) + temp_txt1 + txt.substring(2, 4) + temp_txt2;
img_txt = new String(img_txt.getBytes("8859_1"),"euc-kr");
} else {
img_txt = temp_txt2;
}
}
// BatangChe, DotumChe, GulimChe, GungsuhChe, Serif, SansSerif, Monospaced, Dialog, Dialog Input
g2.setColor( Color.black );
g2.setFont(new Font("DotumChe",Font.BOLD,17));
g2.drawString(img_txt, 8, 44 );
// png 가 훨 깨끗함.
response.setContentType("image/png"); // jpg 로 바꿀때 image/png -> image/jpeg
OutputStream dest = response.getOutputStream();
ImageIO.write( image, "png", dest ); // jpg 로 바꿀때 png -> jpg
dest.flush();
dest.close();
%>
댓글 0
- 전체
- Android+iPhone+etc.
- Apache+Tomcat
- ASP
- ASP.NET
- DataBase
- HTML / CSS
- JavaScript
- JSP
- Linux Server
- PHP
- Raspberry pi
- Windows Server
- WIPI
- Etc.
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
10 | UTF-8 인코딩시의 바이트 수를 계산하는 함수 | taknim | 2012.05.08 | 8421 |
9 | 오라클에서 varchar2(4000) 데이타 넣기 | taknim | 2008.11.25 | 9644 |
8 | 리눅스에서 자바 한글 폰트 설정 | taknim | 2008.03.20 | 8769 |
7 | 쿼리문에서 데이터 길이 초과시 Stream 방식 사용 | taknim | 2007.06.21 | 8192 |
» | 이미지 생성 (이미지에 글자 입력) | taknim | 2006.12.13 | 9635 |
5 | JSP 날짜 연산법 | taknim | 2006.04.10 | 13372 |
4 |
MySQL 연결할때 캐릭터셋을 변경해줘야 할 경우
![]() | taknim | 2005.11.26 | 8034 |
3 | 내부 객체와 액션 태그 | taknim | 2005.10.26 | 8231 |
2 | 한글로 입력받은 값이 깨질 때(문자열 EUC-KR로 변환) | taknim | 2005.10.25 | 9666 |
1 | 윈도우에서 이클립스의 jsp 환경구축 | taknim | 2005.09.30 | 7783 |