views:

86

answers:

2

i have resized image but its quality is low. i heard of bicubic interpolation but i cant get any implementation code!! can sombody provide me that code please!!

+1  A: 

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.

Paul R
A: 
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_INTERPOLATION,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; 
}   

this is my code! Please helm me to make its quality best after upsampling and downsampling!! Thank you for your comment!!

suraj