【问题标题】:How do you create a thumbnail for TIFF file in Java?如何在 Java 中为 TIFF 文件创建缩略图?
【发布时间】:2012-07-16 20:22:27
【问题描述】:

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

使用这个Post 我已经为JPEG 和PNG 创建了缩略图。

【问题讨论】:

  • 你试过什么?您链接的问题中的代码为什么/如何不起作用?贴一些代码。
  • JavaIO 也可以读取 TIFF 文件。请注意,单个文件中可能有多个实际图像。

标签: java


【解决方案1】:
    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。

【讨论】:

  • 忽略答案标签即可。我只想回复
  • edit your question 添加说明/代码,而不是发布“答案”。
猜你喜欢
  • 1970-01-01
  • 2011-02-20
  • 2012-08-11
  • 2011-01-25
  • 2020-09-26
  • 2018-03-21
  • 2010-11-07
  • 1970-01-01
  • 2011-07-24
相关资源
最近更新 更多