What is the best way to scale images in Java?

前端 未结 7 1076
时光取名叫无心
时光取名叫无心 2020-12-30 06:14

I have a web application written in Java (Spring, Hibernate/JPA, Struts2) where users can upload images and store them in the file system. I would like to scale those images

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 06:54

    I tried imgscalr comparing to standard Java 1.6 and I cannot say it is better.

    What I've tried is

    BufferedImage bufferedScaled = Scalr.resize(sourceImage, Method.QUALITY, 8000, height);
    

    and

      Image scaled = sourceImage.getScaledInstance(-1, height, Image.SCALE_SMOOTH);
      BufferedImage bufferedScaled = new BufferedImage(scaled.getWidth(null),  scaled.getHeight(null), BufferedImage.TYPE_INT_RGB);
      bufferedScaled.getGraphics().drawImage(scaled, 0, 0, null);
    

    some 5 minute testing by my eye got impression that second thing (pure Java 1.6) produces better results.

提交回复
热议问题