为什么我下载<高级图像处理图像I/O API RC 1.0 >处理GIF还是有问题,本来动态变成静态啦?JAVA还有好点的图像处理.要支持格式越多越好
解决方案 »
- GVIM中怎样得到当前打开文件的路径?
- 用java程序写两个方法,分别实现把二维数组转换为ArrayList和把ArrayList转换为二维数组.
- 关于导入类
- jFileChooser文件选择器问题
- 使用java读取sqlserver中的text类型时出现中文乱码,请大家帮看看。谢谢。
- RuntimeException和非RuntimeException的区别, who can tell me ??
- 用什么技术实现联众,QQ游戏的风格界面?
- static全局变量的使用会不会造成系统崩溃
- 帮忙看看程序
- 按照如下方法定义一个表格,我该如何动态的修改表格(如添加行和列,applet)
- socket编程郁闷的问题!请教高手
- 那位对 eclipse 比较熟 我这里有2个问题
import java.sql.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;import com.sun.image.codec.jpeg.*;
import com.sun.image.codec.jpeg.JPEGCodec.*;/***
*date:2008-5-12
*author:East(张栋芳)
**/public class ImageHandlerServlet extends HttpServlet{
public Connection getConnection(){
Connection conn=null;
try{
//搞连接
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=pubs";
conn=DriverManager.getConnection(url,"sa","");
}catch(ClassNotFoundException ce){
ce.printStackTrace();
}catch(SQLException se){
se.printStackTrace();
}
return conn;
}
public void doGet(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
try{
conn=getConnection();
pstmt=conn.prepareStatement("select data from uploadfile where id=?");
pstmt.setInt(1,5);
rs=pstmt.executeQuery();
if(rs.next()){
InputStream is=rs.getBinaryStream(1);
//通过JPEG搞JPEG数据流解码器
JPEGImageDecoder jpegDecoder=JPEGCodec.createJPEGDecoder(is);
//解码当前数据流,返回BufferedImage对像
BufferedImage buffImg=jpegDecoder.decodeAsBufferedImage();
//搞到Graphics对像,用于在BufferedImage对像绘制图和文字
Graphics g=buffImg.getGraphics();
//搞ImageIcon logo.gif作为水印图片
ImageIcon imgicon=new ImageIcon("F:logo.gif");
//得到image
Image img=imgicon.getImage();
//水印绘制到图片上
g.drawImage(img,80,80,null);
//设置图形上下文的当前Color为red
g.setColor(Color.red);
//搞字体
Font font=new Font("Courier New",Font.BOLD,20);
//设置图形上下文的字体为指定的字体
g.setFont(font);
//在图片上绘制文字
g.drawString("http://East271536394.com",10,20);
g.dispose();
resp.setContentType("image/jpeg");
ServletOutputStream sos=resp.getOutputStream();
//创建jpeg图像编码器,用于编码内存中的图像数据到JPEG数据输出流
JPEGImageEncoder jpegEncoder=JPEGCodec.createJPEGEncoder(sos);
//编码BufferedImage对像到JPEG数据输出流
jpegEncoder.encode(buffImg);
is.close();
sos.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
}