title: Java zoom in on hi-res image without pixelation or losing drawing
body: <p>I'm using the approach I found in <a href="https://stackoverflow.com/questions/9342233/zoom-in-and-out-of-images-in-java">this answer</a> to create zoom in/out functionality for an image labeling application. However, despite dealing with relatively high resolution images (order of 1500x1500 pixels), the scaling method for zoom leads to pixelation. I checked the image in Windows Photo Viewer and I could definitely zoom in without much pixelation until much more than the 200% zoom I have in my code.</p>
  
  <p>If I resize only compared to the original image (i.e. not cascading each resize call), this works just fine (this is what's in the code snippet). But in order to do this, I lose any drawing functionality. Basically, I would like to be able to do the following:</p>
  
  <ol>
  <li>Load an image</li>
  <li>Draw lines/circles/shapes/etc on it</li>
  <li>Zoom in (maintaining any drawing on the image)</li>
  <li>Draw more</li>
  <li>Zoom in/out at will for whatever reasons I need</li>
  </ol>
  
  <p>In summary, the resizing-for-zoom works. It's preserving any additional drawing at each stage of the zoom that I can't seem to get.</p>
  
  <p>Here's a code snippet of my resize function (<em>heavily</em> influenced by that answer cited before):</p>
  
  <pre><code>private void resizeImage()
  {
      int newImgW = (int)(this.zoom * this.imgW);
      int newImgH = (int)(this.zoom * this.imgH);
      BufferedImage resized = new BufferedImage(newImgW, newImgH, originalImage.getType());
      graphics2D = resized.createGraphics();
      graphics2D.drawImage(this.originalImage, 0, 0, newImgW, newImgH, null);
      this.image = resized;
      repaint();
  }
  </code></pre>