<%@ 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>
分享到:
相关推荐
jsp中生成图片缩略图的代码
jsp上传图片并生成缩略图example upload pictures and zoom it
JSP上传图片并生成缩略图 JSP上传图片并生成缩略图
jsp文件上传 工具MyEclipse 6.0
用JSP实现上传图片自动生成缩略图 很简单的 大家看看把
使用jspsmartupload实现图片的批量上传,并保存到服务器的指定路径,自动生成缩略图,与图片的路径相同。(需要导入jspsmartupload.jar,在工程下的WebContent\WEB-INF\lib中 )
JspSmart 实现JSP上传图片并生成缩略图
看到网上没有同时上传文字和图片的···于是乎自己写了一个···支持图片文字同时上传···并按照时间格式从命名并生成缩略图····
家在网站开发和web应用中常常需要处理图片,因为用户上传的图片往往尺寸大小各不相同,如何能够生成统一尺寸的缩略图往往是让我们头疼的问题,常规的方式基本都是使用后台程序PHP,JSP等处理上传后的图片,针对网站...
制作网站经常会使用到生成文章缩略图的功能,一般的CMS系统比较强大,会有自带的功能,但是Bolg系统就算有这功能,也是或多或少存在一些问题。这里介绍一款php脚本(asp、jsp请绕道),小巧灵活。—— timthumb.php...
图片上传后自动生成一张原图和一缩略图。 对jsp网站非常有用的上传,原码简单,易懂, jsp页面下载下来就可以直接使用。如有不能用与本人联系,邮箱lin3qun@163.com
JSP使用上传文件,并生产高清缩略图示例
3. 支持自动生成缩略图。 4. 支持图片格式批量转换功能。 5. 支持文件批量上传。 6. 支持文件拖拽操作。 7. 支持自定义上传信息。 8. 支持文件拖拽排序功能。 9. 支持文件格式批量转换。 10. 支持打开默认文件夹功能...
可以设置上传文件大孝文件类型、文件路径、生成缩略图,重命名等操作。jspsmartupload.jar上传组件必须放在tomcat\common\lib下面,或者tomcat\shared\lib下面。 数据库在系统里面,自行导入或还原。
使用struts2 上传图片到项目webapps目录下 然后生成缩略图 返回到页面显示缩略图