title: Loading an Image
body: <p>I read in a Game tutorial how to load images, and they did this:</p>
  
  <pre><code>public Image loadImage(... String ref ...) {
    ...
      URL url = this.getClass().getClassLoader().getResource(ref);
      BufferedImage source = ImageIO.read(url);
      GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
      Image image = gc.createCompatibleImage(source.getWidth(), source.getHeight(), Transparency.BITMASK);
  
      image.getGraphics().drawImage(source, 0, 0, null);
      return image;
  }
  </code></pre>
  
  <p>This is absolutely not the best way in terms of usability and clarity (= nobody could find this way just by using their healthy brains). Why is it that complicated? Does it have to be? Why can't image loading be as easy as that:</p>
  
  <pre><code>BufferedImage image = ImageIO.read(ref);
  </code></pre>
  
  <p>Is there an easier way if you just want to load an image in a way that Java automatically does all the default "stuff" it has to do? Is there maybe a reason the author of that code chose another way, because he wanted to achieve some non-default behaviour? When writing an answer please understand that I am looking for an easy way to solve the problem of image loading and also the ability and understanding to apply more complicated means if nessesary.</p>
  
  <p><strong>edit:</strong>
  Also both answers are good presentations of their respective authors oppinions, until now I can't <code>accept</code> one answer, because no answer shows a simpler way and/or explains what exactly is happening.</p>