<%@ 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.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Wang Shiqiang" />
<meta name="keywords" content="Wang Shiqiang" />
<meta name="description" content="" />
</head>
<body>
<%
response.ContentType("text/html;char=gb2312");
request.CharacterEncoding("gb2312");
out.pr("Test for thumbtail picture=");
//-----------------------上传完成开始生成缩略图-------------------------
java.io.File file = java.io.File("E:\\1110168154_58348.jpg");//saveurl); //读入刚才上传文件
String url="E:\\1110168154_58348_min.jpg";//request.getRealPath("/")+url+filename+"_min."+ext; //新缩略图保存地址
Image src = javax.imageio.ImageIO.read(file); //构造Image对象
float tagsize=287;
old_w=src.getWidth(null); //得到源图宽
old_h=src.getHeight(null);
_w=0;
_h=0; //得到源图长
tempsize;
out.pr("<br/>the old width is :"+old_w+" the old height is "+old_h+"<br/>");
float tempdouble;
(old_w>old_h){
tempdouble=old_w/tagsize;
}{
tempdouble=old_h/tagsize;
}
_w=Math.round(old_w/tempdouble);
_h=Math.round(old_h/tempdouble);//计算新图长宽
out.pr("the width is :"+_w+" the height is "+_h+"<br/>");
BufferedImage tag = BufferedImage(_w,_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics.drawImage(src,0,0,_w,_h,null); //绘制缩小后图
FileOutputStream image= FileOutputStream(url); //输出到文件流
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(image);
encoder.encode(tag); //近JPEG编码
image.close;
/*
*/
%>
</body>
</html>
最新评论