title: How to get scaled instance of a bufferedImage
body: <p>I wanted to get scaled instance of a buffered image and I did:</p>
  
  <pre><code>public void analyzePosition(BufferedImage img, int x, int y){   
       img =  (BufferedImage) img.getScaledInstance(getWidth(), getHeight(), Image.SCALE_SMOOTH);
  ....
  }
  </code></pre>
  
  <p>but I do get an exception:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: sun.awt.image.ToolkitImage cannot be cast to java.awt.image.BufferedImage
      at ImagePanel.analyzePosition(ImagePanel.java:43)
  </code></pre>
  
  <p>I wanted then to cast to <code>ToolkitImage</code> then use the method <code>getBufferedImage</code> I read about in other articles. The problem is there is no class such as <code>sun.awt.image.ToolkitImage</code> I cannot cast to it because Eclipse does not even see this class. I use <code>Java 1.7</code> and <code>jre1.7</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/9jlJk.png" alt="enter image description here"></p>