woensdag 6 april 2011

[Java] Resizing a BufferedImage

Here's a small piece of code that might aid you in resizing a BufferedImage. Most methods I saw on the internet just took the BufferedImage and resized it to fit the screen. This method will return a new bufferedImage with the new width and height. 





  1. public static BufferedImage resize(BufferedImage img, int newW, int newH) {  
  2.         int w = img.getWidth();  
  3.         int h = img.getHeight();  
  4.         BufferedImage dimg = dimg = new BufferedImage(newW, newH, img.getType());  
  5.         Graphics2D g = dimg.createGraphics();  
  6.         g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,     RenderingHints.VALUE_INTERPOLATION_BILINEAR);  
  7.         g.drawImage(img, 00, newW, newH, 00, w, h, null);  
  8.         g.dispose();  
  9.         return dimg;  
  10.     }  

Geen opmerkingen:

Een reactie posten