0

有人可以帮忙用一些代码来为 Java 中的 TIFF 创建缩略图。

使用这篇文章,我为 JPEG 和 PNG 创建了缩略图。

4

1 回答 1

0
    BufferedImage image = ImageIO.read(aFile);
    BufferedImage thumbnNailImage = new BufferedImage(width, height,
            BufferedImage.TYPE_INT_RGB);

    Graphics2D g2 = thumbnNailImage.createGraphics();
    g2.fillRect(0, 0, width, height);

    double xScale = (double) width / image.getWidth();
    double yScale = (double) height / image.getHeight();
    double scale = Math.min(xScale, yScale);

    double x = (width - image.getWidth() * scale) / 2;
    double y = (height - image.getHeight() * scale) / 2;
    AffineTransform at = AffineTransform.getScaleInstance(x, y);
    at.scale(scale, scale);
    g2.drawRenderedImage(image, at);
    g2.dispose();
    return thumbnNailImage;

读取 ImageIO.read(aFile); 时 总是返回 null。

于 2012-07-16T12:22:27.280 回答