在JAVA中为TIFF图像创建缩略图

时间:2012-08-10 11:33:53

标签: java tiff jai javax.imageio

  

可能重复:
  Can't read and write a TIFF image file using Java ImageIO standard library

有人可以帮助我们使用一些代码来创建Java中的TIFF缩略图。 使用此Post已创建JPEG和PNG缩略图。我使用下面的代码为PNG和JPEG

创建了thumbanail
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;  

0 个答案:

没有答案