title: Java Image Resize BufferedImage doesn't draw
body: <p>I am trying to resize an Image, the save it as a BufferedImage. If I do not scale the image, I works fine.</p>
  
  <p>With the following code, a filename is passed in and converted to a BufferedImage this works fine Using <code>g.drawImage(img, x, y, null);</code> where img is the BufferedImage</p>
  
  <pre><code>public Sprite(String filename){
      ImageIcon imgIcon = new ImageIcon(filename);
      int width = imgIcon.getIconWidth();
      int height = imgIcon.getIconHeight();
      BufferedImage bimg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics bg = bimg.getGraphics();
      bg.drawImage(imgIcon.getImage(), 0, 0, null);
      bg.dispose();
      this.sprite = bimg;
  }
  </code></pre>
  
  <p>The following method here does not work, it takes a filename, and a resize width. It resizes it, then converts it to a BufferedImage, but it does not work using <code>g.drawImage(img, x, y, null);</code> again where img is the BufferedImage.</p>
  
  <pre><code>public Sprite(String filename, int width){
      ImageIcon imgIcon = new ImageIcon(filename);
      Image img = imgIcon.getImage();
      float h = (float)img.getHeight(null);
      float w = (float)img.getWidth(null);
      int height = (int)(h * (width / w));
      Image imgScaled = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
  
      BufferedImage bimg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics bg = bimg.getGraphics();
      bg.drawImage(imgScaled, 0, 0, null);
      bg.dispose();
      this.sprite = bimg;
  }
  </code></pre>
  
  <p>So my question is, why isn't the second block working?</p>