title: how to resize Image in java?
body: <p>Hello I have a QR code Image , and I want to resize it , when I try to resize it to a small image using this code , I always get a blury image , and the QR code is no longer valid when I scan it , but it works fine when I resize to a big sized images with the same code :</p>
  
  <pre><code>public BufferedImage getScaledInstance(BufferedImage img,
                                     int targetWidth,
                                     int targetHeight,
                                     Object hint,
                                     boolean higherQuality)
  {
  int type = (img.getTransparency() == Transparency.OPAQUE) ?
      BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
  BufferedImage ret = (BufferedImage)img;
  int w, h;
  if (higherQuality) {
      // Use multi-step technique: start with original size, then
      // scale down in multiple passes with drawImage()
      // until the target size is reached
      w = img.getWidth();
      h = img.getHeight();
  } else {
      // Use one-step technique: scale directly from original
      // size to target size with a single drawImage() call
      w = targetWidth;
      h = targetHeight;
  }
  
  do {
      if (higherQuality &amp;&amp; w &gt; targetWidth) {
          w /= 2;
          if (w &lt; targetWidth) {
              w = targetWidth;
          }
      }
  
      if (higherQuality &amp;&amp; h &gt; targetHeight) {
          h /= 2;
          if (h &lt; targetHeight) {
              h = targetHeight;
          }
      }
  
      BufferedImage tmp = new BufferedImage(w, h, type);
      Graphics2D g2 = tmp.createGraphics();
      g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
      //        g2.setRenderingHint(RenderingHints.KEY_DITHERING, hint);
      g2.drawImage(ret, 0, 0, w, h, null);
      g2.dispose();
  
      ret = tmp;
  } while (w != targetWidth || h != targetHeight);
  
  return ret;
  }
  </code></pre>
  
  <p>what is the problem , I don't exactly understand , please give me at least a hint , thank you </p>