• 相关软件
    >缩小图片的高和宽 创建者:webmaster 更新时间:2005-06-04 19:51

    <%@page import="java.awt.image.*" import="java.awt.Image" import="java.awt.Image"%>
    <%@page import="javax.imageio.ImageIO" import="java.io.File" import="java.awt.geom.AffineTransform" import="java.awt.geom.AffineTransform"%>
    <%
    new UploadImg().CreateThumbnail();
    %>
    <%!
    class UploadImg {
    public UploadImg()
    {}
    /**
    * @param fromdir \u56FE钴戢惴偻\u5F55
    * @param todir \u5904租钴\u56FE痦郫偻\u5F55
    * @param imgfile 戢惴\u56FE
    * @param sysimgfile \u5904租钴\u56FE冼遂伲铖\u7F00
    *
    */
    String fromdir="D:/";
    String todir="D:/";
    String imgfile="11872.jpg";
    String sysimgfile="abc";
    public boolean CreateThumbnail() throws Exception {
    //ext憷\u56FE钴太阋 gif JPG png
    String ext = "";
    double Ratio = 0.0;
    java.io.File F = new java.io.File(fromdir, imgfile);
    if (!F.isFile())
    throw new Exception(F + " is not image file error in CreateThumbnail!");
    //庀嗷鼢\u65AD呔\u4F20钴\u56FE憷gif\u8FD8憷JPG ImageIO颃姻\u5C06gif\u8F6C\u6362\u4E3Apng
    // if (isJpg(imgfile)) {
    ext = "jpg";
    // }
    // else {
    // ext = "png";
    // }
    File ThF = new File(todir, sysimgfile + "." + ext);
    BufferedImage Bi = ImageIO.read(F);
    //剩\u8BBE\u56FE\u5BBD 驮 跆愚\u4E3A120 120
    Image Itemp = Bi.getScaledInstance(120, 120, Bi.SCALE_SMOOTH);
    if ((Bi.getHeight() > 120) || (Bi.getWidth() > 120)) {
    if (Bi.getHeight() > Bi.getWidth())
    Ratio = 120.0 / Bi.getHeight();
    else
    Ratio = 120.0 / Bi.getWidth();
    }
    System.out.println(Ratio);
    AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(Ratio, Ratio), null);
    Itemp = op.filter(Bi, null);
    try {
    ImageIO.write((BufferedImage) Itemp, ext, ThF);
    }
    catch (Exception ex) {
    throw new Exception(" ImageIo.write error in CreatThum.: " + ex.getMessage());
    }
    return (true);
    }
    }
    %>
    相关文章
    本页查看次数: