开发者

Image Resampling Bicubic Interpolation Java

I have resized image but its quality is low. i heard of bicubic interpolation but i cant get any implementation code. Here is my code:

private static BufferedImage resize(BufferedImage image, int width, int height) 
{ 
    int w = image.getWidth(), h = image.getHeight();
    int type = image.getType() == 0? BufferedImage.TYPE_INT_ARGB : image.getType();
    BufferedImage resizedImage = new BufferedImage(width, height, type);
    Graphics2D g = resizedImage.createGraphics();
    g.setComposite(AlphaComposite.Src);
    g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLA开发者_开发百科TION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);

    //g.drawImage(image, 0, 0, width, height, null);
    g.scale((double)width/w,(double)height/h);
    g.drawRenderedImage(image, null);
    g.dispose();
    return resizedImage; 
}   

I want to get the best quality after upsampling and downsampling.


Bicubic interpolation and other interpolation schemes are needed only when you need to resize by some non-integer scale factor. What you're probably missing is that you need to filter your image prior to downsampling (when shrinking) or filter after upsampling (when expanding) to avoid aliasing artefacts, which is an entirely different problem. This applies to both integer and non-integer scale factors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜