首页 > 其他 > 详细

Java处理图片

时间:2014-03-04 00:29:28      阅读:457      评论:0      收藏:0      [点我收藏+]

经常在网上找处理图片的方法,总是感觉很乱,以下代码的方法不错,总结分享下:

bubuko.com,布布扣
/**
     * @param fromFileStr 源图片路径
     * @param saveToFileStr 目标图片目录
     * @param sysimgfile 目标图片名(不带图片后缀)
     * @param suffix 目标图片后缀
     * @param width 目标图片宽
     * @param height 目标图片高
     * @throws Exception
     * @author 李敏
     */
    public static void createThumbnail(String fromFileStr,
            String saveToFileStr, String sysimgfile, String suffix, int width,
            int height) throws Exception {
        double Ratio = 0.0;
        File F = new File(fromFileStr);
        if (!F.isFile())
            throw new Exception(F
                    + " is not image file error in CreateThumbnail!");
        File ThF = new File(saveToFileStr, sysimgfile + "." + suffix);
        BufferedImage Bi = ImageIO.read(F);
        Image Itemp = Bi.getScaledInstance(width, height, Bi.SCALE_SMOOTH);
        if ((Bi.getHeight() > width) || (Bi.getWidth() > height)) {
            if (Bi.getHeight() > Bi.getWidth())
                Ratio = (double) width / Bi.getHeight();
            else
                Ratio = (double) height / Bi.getWidth();
        }
        AffineTransformOp op = new AffineTransformOp(AffineTransform
                .getScaleInstance(Ratio, Ratio), null);
        Itemp = op.filter(Bi, null);
        try {
            ImageIO.write((BufferedImage) Itemp, suffix, ThF);
        } catch (Exception ex) {
            throw new Exception(" ImageIo.write error in CreatThum.: "
                    + ex.getMessage());
        }
    }
bubuko.com,布布扣

Java处理图片,布布扣,bubuko.com

Java处理图片

原文:http://www.cnblogs.com/jdxf/p/image.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!