這裏是原始圖像:http://rank.my/public/images/uploaded/orig-4193395691714613396.png爲什麼在Java中縮小後圖像看起來很糟糕?
這裏,它被縮小爲300x225:
http://rank.my/public/images/uploaded/norm-4193395691714613396.png
這裏,它被縮小到150x112:
http://rank.my/public/images/uploaded/small-4193395691714613396.png
由於你可以看到,300x225看起來很糟糕,而150x112看起來很糟糕。這裏是我用來縮小圖像的代碼:
private static BufferedImage createResizedCopy(final BufferedImage source, final int destWidth,
final int destHeight) {
final BufferedImage resized = new BufferedImage(destWidth, destHeight, source.getType());
final Graphics2D bg = resized.createGraphics();
bg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
bg.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
final float sx = (float) destWidth/source.getWidth();
final float sy = (float) destHeight/source.getHeight();
bg.scale(sx, sy);
bg.drawImage(source, 0, 0, null);
bg.dispose();
return resized;
}
我在做什麼錯在這裏?圖像縮放不一定要特別快,質量絕對是速度優先。我使用錯誤的技術?
@MusiGenesis:我認爲你的答案被刪除是優秀的,我希望你能取消刪除。 – 2011-02-11 04:06:12
鏈接已死,請用imgur或其他類似主機:) – alex 2012-08-21 05:13:43
鏈接已備份 - 對不起 – sanity 2012-08-23 16:42:33