JAVA 图像处理 为什么我下载<高级图像处理图像I/O API RC 1.0 >处理GIF还是有问题,本来动态变成静态啦?JAVA还有好点的图像处理.要支持格式越多越好 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*;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(); } }} 设置java 的classpath问题,谢谢 使用synth遇到的问题 初学基础作业里一个抽象类构造方法的问题,我这个写不出来,所以也不能compile java 实现 在线升级 功能 和 本地升级功能 【SWT】取消table中选中的项 JAVA6个基础题,希望有人详细讲解下. 这三句话定义了3个什么对象?请教! 关于源文件名和其中的类名 读Struts2 的源码的一点疑问,请专家解答。 用java怎样封锁学生机器的tcp连接? 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();
}
}
}