|
|
| 首页 | 技术文章 | 软件下载 | 博客 | 论坛 | 精品教程 | 黑客动画 | 视频资源 | 在线服务 | 黑客游戏 | | ||||
|
|
||||||||
|
||||||||
|
|||||
| 生成缩小jpg图片程序 | |||||
作者:不详 文章来源:CnXHacker.Net 点击数: 更新时间:2007-5-30 ![]() |
|||||
|
import java.io.File; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.imageio.ImageIO; import java.awt.image.AffineTransformOp; import java.awt.geom.AffineTransform; import java.awt.Image; public class ZoomPicture{ public static void main(String arg[]){ String filePath = "g:/图片.jpg"; // 图片的位置 int height=50; int width=150; Icon icon = null; try{ icon = getFixedBoundIcon(filePath,height,width); }catch(Exception e){ System.out.println("exception : " + e); } System.out.println(" ### " + icon); //生成新图片的位置; } public static Icon getFixedBoundIcon(String filePath, int height, int width) throws Exception{ double Ratio=0.0; //缩放比例 File F = new File(filePath); if (!F.isFile()) throw new Exception (F+" is not image file error in getFixedBoundIcon!"); Icon ret = new ImageIcon(filePath); BufferedImage Bi = ImageIO.read(F); if ((Bi.getHeight()>height) || (Bi.getWidth()>width)){ if (Bi.getHeight()>Bi.getWidth()){ Ratio = (new Integer(height)).doubleValue() /Bi.getHeight(); } else { Ratio = (new Integer(width)).doubleValue()/Bi.getWidth(); } int lastLength = filePath.lastIndexOf("."); String subFilePath = filePath.substring(0,lastLength); String fileType = filePath.substring(lastLength); File zoomFile = new File(subFilePath+"_"+height +"_"+width+fileType); Image Itemp = Bi.getScaledInstance (width,height,Bi.SCALE_SMOOTH); AffineTransformOp op = new AffineTransformOp (AffineTransform.getScaleInstance(Ratio, Ratio), null); Itemp = op.filter(Bi, null); try { ImageIO.write((BufferedImage)Itemp, "jpg", zoomFile); ret = new ImageIcon(zoomFile.getPath()); }catch (Exception ex) { System.out.println("######## here error : " + ex); } } return ret; } } |
|||||
| 文章录入:IceRiver 责任编辑:IceRiver | |||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | |||||
| 最新热点 | 最新推荐 | 相关文章 | ||
| 牛X下载者生成器生成的网页木 黑客入侵高校 篡改百余学生成 服务端生成技术的思考 服务端生成技术的思考 用内存流,文件流,资源生成 身份证生成器:互联网“实名 木马生成器不能随便碰 “身份证生成器”挑战网络实 网上出现身份证生成器 瞬间生 身份证生成器现身网络 实名制 |
网友评论:(只显示最新5条。评论内容只代表网友观点,与本站立场无关!) |
| 关于我们 - 版权声明 - 帮助(?) - 广告服务 - 联系我们 - 友情链接 - 用户注册 - | Powered by ICE RIVER - STUDIO |
| » CnXHacker.CoM | © CopyRight 2002-2006, CnXHacker.CoM™, Inc. All Rights Reserved. |