Sunday 26 May 2013

How Text Message Converted into Image format Like .BMP, .JPEG, .JPG using jsp



This code save as "img.jsp" and use it.


<%@ page import="java.io.*"
%><%@ page import="java.awt.*"
%><%@ page import="java.awt.image.*"
%><%@ page import="javax.imageio.ImageIO"
%><%@ page import="java.util.*"
%>
<%
int width=500;
int height=300;
int colSpaceDefault[]={30,60,90,95};
try{
//Color background = new Color(233,211,136);
Color background = new Color(156,250,140);
String[] chars= {"501 Mussoorie 15.30 15.35","531 New Delhi 16.15 16.35","631 Chandighar 11.30 14.35","501 Mumbai 15.30 10.35","211 Lucknow 12.30 12.45","510 Bangalore 12.30 10.10"};

Color fbl = new Color(0,0,0);
Font fnt=new Font("VERDANA",1,15);
BufferedImage cpimg =new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = cpimg.createGraphics();

g.setColor(background);
g.fillRect(0,0,width,height);
g.setColor(fbl);
g.setFont(fnt);

int j=0;
int length = 20;

for(int i=0;i<chars.length;i++){
j=25*(i+1);
g.drawString(chars[i],10,j);
}
g.setColor(background);
response.setContentType("image/bmp");   

OutputStream strm = response.getOutputStream();
ImageIO.write(cpimg,"bmp",strm);
strm.flush();
strm.close();
return;
}catch(Exception _objEx){

}

%>


No comments:

Post a Comment