| |
| jsp中生成图片缩略图的代码 |
| |
发布者: 发布时间:2007-02-13 |
|
|
<%@ 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>
|
| (转载文章请保留出处:北天JAVA技术网(www.java114.com)) |
| |
| 更多精彩文章: |
| JSP图形验证码-汉字 |
| Jsp基础知识总结 |
| 一个简单的用JAVA实现的屏幕抓图(源代码) |
| 基于目录结构认证的问题 |
| 一个判断session是否过期的小技巧 |
| 一道华为JAVA比武大赛试题,你能解答吗? |
| |
| 最近评论: |
|
|
| 你曾悄悄的来过! |
| wow gold,wow gold,wow gold,ffxi gil max(2338) |
|
|
| 冰封的往事! |
| wow power leveling,wow gold,wow power leveling,wow gold
max(7091) |
|
|
| 冰封的往事! |
| wow power leveling,wow gold,WoW Gold,wow gold
max(1512) |
|
|
| 飞舞的传奇! |
| 传世私服,传世私服.传奇世界私服传奇世界私服,传世私服传世私服, 传奇世界私服传奇世界私服.传奇私服传奇私服. max(2996) |
|
|
| |
| 免责声明:该文章由网友发表,如果对您造成侵权,请联系站长。 |
|