0

Can someone please help with some code for creating a thumbnail for a TIFF in Java.

Using this Post I have created thumbnail for JPEG and PNG.

Community
  • 1
  • 1
Selvanayagam
  • 73
  • 1
  • 11

1 Answers1

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;

When reading ImageIO.read(aFile); always returns null.

Selvanayagam
  • 73
  • 1
  • 11