zoukankan      html  css  js  c++  java
  • java创建缩略图

    public void createSmallPic(int height, int width){
      String smallPath = "smallPath"; // 小图存放目录   
      if(!new File(smallPath).exists()) { 
        new File(smallPath).mkdirs(); 
      }
      double ratio = 0.0;
      File file = new File("d:/a.jpg"); // 大图路径
      BufferedImage bi = ImageIO.read(file); // 读取大图
      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();
        }
        file = new File(smallPath + File.separator + file.getName() + "_" + 
                             height + "_" + width + ".jpg"); // 缩略图路径
        Image img = bi.getScaledInstance(width, height, bi.SCALE_SMOOTH);
        AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(ratio, ratio), null);
        img = op.filter(bi, null);
        ImageIO.write((BufferedImage) img, "jpg", file);
      }
    }
  • 相关阅读:
    git 镜像地址
    IntelliJ IDEA 2019 控制台中文乱码问题
    LINUX配置本地YUM源
    动态添加js的代码
    Java 多线程
    Java I/O系统
    Java 中的容器 Collection 和 Map
    Java 数组
    javaweb的四大作用域
    三层 转自http://git.oschina.net/tzhsweet/superui
  • 原文地址:https://www.cnblogs.com/makar/p/3250852.html
Copyright © 2011-2022 走看看