Ignore:
Timestamp:
Apr 30, 2011, 1:37:01 PM (13 years ago)
Author:
mlg
Message:

Modifications to try to have a better image quality on resizing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/ImagesUtil.java

    r9893 r10698  
    5151            .getLog(ImagesUtil.class);
    5252
     53    private static final GraphicsConfiguration CONFIGURATION = GraphicsEnvironment.getLocalGraphicsEnvironment()
     54            .getDefaultScreenDevice().getDefaultConfiguration();
     55
     56    public static void main(String[] args) throws IOException {
     57        scale("/home/mael/Bureau/test.png", "test4.jpg", 1999, 1999);
     58    }
     59
    5360    /**
    5461     * rotates an image
     
    101108     */
    102109    public static boolean scale(String filePath, String tempName, int width, int height) throws IOException {
    103         File file = new File(filePath);
    104110        InputStream imageStream = new BufferedInputStream(new FileInputStream(filePath));
    105111        Image image = (Image) ImageIO.read(imageStream);
     
    117123            width = (int) (height * imageRatio);
    118124        }
    119         BufferedImage thumbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     125        //      BufferedImage thumbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     126        BufferedImage thumbImage = createCompatibleImage(ImageIO.read(new File(filePath)), width, height);
    120127        Graphics2D graphics2D = thumbImage.createGraphics();
    121128        graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    122129        graphics2D.drawImage(image, 0, 0, width, height, null);
    123 
     130        graphics2D.dispose();
    124131        //      ImageIO.write(thumbImage, "jpg", new FileOutputStream(System.getProperty("java.io.tmpdir") + "/" + tempName));
    125132        saveImage(System.getProperty("java.io.tmpdir") + "/" + tempName, thumbImage);
    126133        return true;
    127134
     135    }
     136
     137    public static BufferedImage createCompatibleImage(BufferedImage image, int width, int height) {
     138        return CONFIGURATION.createCompatibleImage(width, height, image.getTransparency());
    128139    }
    129140
Note: See TracChangeset for help on using the changeset viewer.