<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" import="java.util.*" %>
<%@ page language="java" import="java.io.*" %>
<%@ page language="java" import="java.awt.*" %>
<%@ page language="java" import="java.awt.image.*" %>
<%@ page language="java" import="com.sun.image.codec.jpeg.*" %>
http://ww***.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
ou***rint("==================Test for thumbtail picture=============");
//-----------------------上传完成,开始生成缩略图-------------------------
ja***io.File file = new ja***io.File("E:\1110168154_58348.jpg");//saveurl); //读入刚才上传的文件
String newurl="E:\1110168154_58348_min.jpg";//***uest.getRealPath("/")+url+filename+"_min."+ext; //新的缩略图保存地址
Image src = ja***.imageio.ImageIO.read(file); //构造Image对象
float tagsize=287;
int ol***=src.getWidth(null); //得到源图宽
int ol***=src.getHeight(null);
int new_w=0;
int new_h=0; //得到源图长
int tempsize;
ou***rint("
the old width is :"+old_w+" the old height is "+old_h+"
");
float tempdouble;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
ne***=Math.round(old_w/tempdouble);
ne***=Math.round(old_h/tempdouble);//计算新图长宽
ou***rint("the new width is :"+new_w+" the new height is "+new_h+"
");
BufferedImage tag = new BufferedImage(new_w,new_h,Bu***redImage.TYPE_INT_RGB);
ta***etGraphics().drawImage(src,0,0,new_w,new_h,null); //绘制缩小后的图
FileOutputStream newimage=new FileOutputStream(newurl); //输出到文件流
JPEGImageEncoder encoder = JP***odec.createJPEGEncoder(newimage);
en***er.encode(tag); //近JPEG编码
ne***age.close();
/*
*/
%>
上一篇: jsp实现图形验证码
下一篇: JSP高访问量下的计数程序