首 页文章中心下载中心繁體中文
设为首页
加入收藏
联系我们
您当前的位置:开源盛世-源代码下载网 -> 文章中心 -> 其他编程 -> Java技术 -> 文章内容 退出登录 用户管理
栏目导航
· VC# 技术 · Delphi技术
· Java技术 · 通用算法
· 编程相关
热门文章
· Tab Control控件使用...
· 学生档案管理系统
· [图文] 排列组合公式
· UTF-8与GB2312之间的...
· DirectShow下载安装...
· Virtual PC 在PAE模...
· Windows2000终端服务...
· MapInfo上的GIS系统...
· Mapbasic参考手册索...
· MapX应用开发中文讲...
相关文章
生成缩小jpg图片程序
作者:佚名  来源:vscodes.com整理  发布时间:2005-12-16 13:00:05  发布人:Polaris

减小字体 增大字体

import java.awt.image.BufferedImage;
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;
}
}


End of《生成缩小jpg图片程序》

[] [返回上一页] [打 印] [收 藏]
下一篇文章:eclipse启动过程
 
∷相关“生成缩小jpg图片程序”文章评论∷
(评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 网站目录 鄂ICP备06007162
开源盛世 版权所有Copyright © 2003-2005 VSCodes.Com. All Rights Reserved.