| 首页 | 技术文章 | 软件下载 | 博客 | 论坛 | 精品教程 | 黑客动画 | 视频资源 | 在线服务 | 黑客游戏 | 

您现在的位置: 中国X黑客小组 >> 技术文章 >> 编程技术 >> 综合其它 >> 文章正文 用户登录 新用户注册
  生成缩小jpg图片程序          【字体:
生成缩小jpg图片程序
作者:不详    文章来源:CnXHacker.Net    点击数:    更新时间:2007-5-30    
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;
}
}

文章录入:IceRiver    责任编辑:IceRiver 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    牛X下载者生成器生成的网页木
    黑客入侵高校 篡改百余学生成
    服务端生成技术的思考
    服务端生成技术的思考
    用内存流,文件流,资源生成
    身份证生成器:互联网“实名
    木马生成器不能随便碰
    “身份证生成器”挑战网络实
    网上出现身份证生成器 瞬间生
    身份证生成器现身网络 实名制
      网友评论:(只显示最新5条。评论内容只代表网友观点,与本站立场无关!)
    Powered by ICE RIVER - STUDIO
    » CnXHacker.CoM   © CopyRight 2002-2006, CnXHacker.CoM™, Inc. All Rights Reserved.