【问题标题】:High Quality thumbnail in javajava中的高质量缩略图
【发布时间】:2011-10-11 13:32:20
【问题描述】:

我尝试了下面的代码来生成缩略图。

我能够获得缩略图,但质量不高。请任何人都可以帮助我生成高质量的缩略图吗?原始图像质量很高。

BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setBackground(Color.WHITE);
graphics2D.setPaint(Color.WHITE); 
graphics2D.fillRect(0, 0, thumbWidth, thumbHeight);
graphics2D.setComposite(AlphaComposite.Src);

graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
graphics2D.dispose();      
File file = new File(thumbnailFile);
if (javax.imageio.ImageIO.write(thumbImage, "JPG", file))
    return file;

【问题讨论】:

  • 当您说质量时,您的意思是什么?分辨率是否与预期不同,或者图像是否模糊或什么?
  • 我得到的图像是模糊的。不清楚。

标签: java image-processing thumbnails


【解决方案1】:

【讨论】:

  • 请不要发布仅链接的答案,但也要尝试在答案中添加一些相关部分。链接可能会死,等等。
  • @RobAu 这些是官方文档,如果您对它有强烈的感觉,请随时更新它们。我不再关注这个问题
【解决方案2】:

我遇到了同样的问题,发现这篇很棒的文章末尾有示例代码和示例图片:

http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html

【讨论】:

  • 请不要发布仅链接的答案,但也要尝试在答案中添加一些相关部分。链接可能会死掉,等等——RobAu 刚刚编辑
【解决方案3】:

检查这个I found best jar file here

public static javaxt.io.Image resizeThumbnailImage(javaxt.io.Image image, int width, int height) {

    Integer imgWidth = image.getWidth();
    Integer imgHeight = image.getHeight();
    Double imgRatio = (imgWidth.doubleValue() / imgHeight.doubleValue());
    logger.info("\n======= imgRatio " + imgRatio);
    if (imgRatio >= 2) {
        image.setWidth(width - 1);

    } else if (imgRatio < 1) {
        image.setHeight(300);

    } else {
        Double expectedHeight = (imgRatio * (height / ProjectConstant.THUMBNAIL_IMG_ASPECT_RATIO));
        image.setHeight(expectedHeight.intValue());

        if (image.getWidth() > width) {
            image.setWidth(width - 20);
        }
    }
    logger.info("=======after Processing  image Width  " + image.getWidth()+" Hight "+image.getHeight());

    return image;
}

我的不变

public static final double THUMBNAIL_IMG_ASPECT_RATIO = 1.4;

【讨论】:

  • 如果有人需要更多信息,请发表评论
猜你喜欢
  • 2011-10-11
  • 2014-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-21
  • 1970-01-01
相关资源
最近更新 更多