• 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);
      }
    }
  • 相关阅读:
    软件课程设计(3)
    软件课程设计(2)
    软件课程设计(1)
    继往开来第五天
    勤勤恳恳第四天
    撸起袖子第三天
    厉兵秣马第二天
    项目初定第一天
    Magic-Club第五天
    Magic-Club第四天
  • 原文地址:https://www.cnblogs.com/makar/p/3250852.html
Copyright © 2020-2023  润新知