title: Resize the ImageIcon or the Buffered Image?
body: <p>I'm trying to resize an image to 50 * 50 pixels. Im taking the images, from their path stored in a Database. I have no problem getting the images and displaying them. I'm just wondering at what point should I try resize the images. Should it be when I get the image as a buffered image, or just try to resize the icon?</p>
  
  <pre><code>while (rs.next()) {
                          i = 1;
                          imagePath = rs.getString("path");
                              System.out.println(imagePath + "\n");
                              System.out.println("TESTING - READING IMAGE");
                          System.out.println(i);
  
                          myImages[i] = ImageIO.read(new File(imagePath));
                          **resize(myImages[i]);**
  
                          imglab[i] = new JLabel(new ImageIcon(myImages[i]));
                          System.out.println(i);
                          imgPanel[i]= new JPanel();
                          imgPanel[i].add(imglab[i]);
                          loadcard.add(imgPanel[i], ""+i);     
                          i++; 
  </code></pre>
  
  <p>The above code is retrieving the image and assigning it to an ImageIcon, then JLabel. I have attempted to resize the buffered image, by using the below resize method. Could you guys, shed any light on why this isn't working for me? Not getting any errors, just the image remains its original size.</p>
  
  <pre><code>public static BufferedImage resize(BufferedImage img) {  
            int w = img.getWidth();  
            int h = img.getHeight(); 
            int newH = 50;
            int newW = 50;
            BufferedImage dimg = dimg = new BufferedImage(newW, newH, img.getType());  
            Graphics2D g = dimg.createGraphics();  
            System.out.println("Is this getting here at all " + dimg);
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);  
            g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);  
            g.dispose();  
            return dimg;
            }
  </code></pre>