title: How to resize Image in Java with same or lower DPI
body: <p>I am trying to resize jpg Image files in Java. For this I am using Scalr.
  I have around 16MB image with 6000x4000 Resolution and 350 dpi.</p>
  
  <p>When I resize it to 4500 width, it downscales the DPI also to 96.</p>
  
  <p>This is the code I am using:</p>
  
  <pre><code>    Scalr.resize(img, Scalr.Method.ULTRA_QUALITY, 4500, Scalr.OP_ANTIALIAS);
  </code></pre>
  
  <p>I tried it without any library with the code as:</p>
  
  <pre><code>    private static BufferedImage resizeImageWithHint(BufferedImage originalImage, int type, int IMG_WIDTH,
          int IMG_HEIGHT) {
  
      BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
      Graphics2D g = resizedImage.createGraphics();
      g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
      g.dispose();
      g.setComposite(AlphaComposite.Src);
  
      g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  
      return resizedImage;
  }
  </code></pre>
  
  <p>But the result was same. So how can I resize the images with dpi around 150 if possible and same 350 dpi if not possible.</p>