Advertisement
ThinMatrix

Image Resizing

Feb 3rd, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1.     private static ImageIcon resizeImage(ImageIcon original, int iconWidth, int iconHeight) {
  2.         Image img = original.getImage();
  3.         Image resized = getScaledImage(img, iconWidth, iconHeight);
  4.         return new ImageIcon(resized);
  5.     }
  6.  
  7.     private static Image getScaledImage(Image srcImg, int w, int h) {
  8.         BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
  9.         Graphics2D g2 = resizedImg.createGraphics();
  10.         g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
  11.                 RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  12.         g2.drawImage(srcImg, 0, 0, w, h, null);
  13.         g2.dispose();
  14.         return resizedImg;
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement