title: How to convert ImageIcon to Image?
body: <p>I have grabbed the imageicon from my project src files like this:</p>
  
  <pre><code> icon = new ImageIcon(ViewDetailsV.class.getResource("/brandnew/images/male_avatar.jpg"));
  </code></pre>
  
  <p>Then I want to put into this line so as to resize to the size of the label:</p>
  
  <pre><code>lblPhotoField.setIcon(new ImageIcon(ScaledImage(icon, lblPhotoField.getWidth(), lblPhotoField.getHeight()));
  </code></pre>
  
  <p>But I need the "icon" to be image , not imageicon as the method ScaledImage takes in Image parameter instead of ImageIcon.</p>
  
  <pre><code> private Image ScaledImage(Image img, int w, int h){
      BufferedImage resizedImage = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
  
      Graphics2D g2 = resizedImage.createGraphics();
      g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      g2.drawImage(img, 0,0,w,h,null);
      g2.dispose();
      return resizedImage;
  }
  </code></pre>
  
  <p>Yup I did tried changing the return value to ImageIcon but it gave me errors. So I'm now focusing on how to convert ImageIcon to Image so I can put it in the method line, getting the icon and set my label it like this:</p>
  
  <pre><code> lblPhotoField.setIcon(icon);
  </code></pre>