<%@ 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.*" %>
<!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.setcontenttype("text/html;charset=gb2312");
request.setcharacterencoding("gb2312");
out.print("==================test for thumbtail picture=============");
//-----------------------上傳完成,開始生成縮略圖-------------------------
java.io.file file = new java.io.file("e://1110168154_58348.jpg");//saveurl); //讀入剛才上傳的文件
string newurl="e://1110168154_58348_min.jpg";//request.getrealpath("/")+url+filename+"_min."+ext; //新的縮略圖保存地址
image src = javax.imageio.imageio.read(file); //構造image對象
float tagsize=287;
int old_w=src.getwidth(null); //得到源圖寬
int old_h=src.getheight(null);
int new_w=0;
int new_h=0; //得到源圖長
int tempsize;
out.print("<br/>the old width is :"+old_w+" the old height is "+old_h+"<br/>");
float tempdouble;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=math.round(old_w/tempdouble);
new_h=math.round(old_h/tempdouble);//計算新圖長寬
out.print("the new width is :"+new_w+" the new height is "+new_h+"<br/>");
bufferedimage tag = new bufferedimage(new_w,new_h,bufferedimage.type_int_rgb);
tag.getgraphics().drawimage(src,0,0,new_w,new_h,null); //繪制縮小后的圖
fileoutputstream newimage=new fileoutputstream(newurl); //輸出到文件流
jpegimageencoder encoder = jpegcodec.createjpegencoder(newimage);
encoder.encode(tag); //近jpeg編碼
newimage.close();
/*
*/
%>
</body>
</html>
新聞熱點
疑難解答