title: How to rescale and save an BufferedImage
body: <p>I got a BufferedImage and want to rescale it before saving it as an jpg/png.</p>
  
  <p>I got the following code:</p>
  
  <pre><code>private BufferedImage rescaleTo(BufferedImage img,int minWidth,int minHeight) {
      BufferedImage buf = toBufferedImage(img.getScaledInstance(minWidth, minHeight, Image.SCALE_DEFAULT));
      BufferedImage ret = new BufferedImage(buf.getWidth(null),buf.getHeight(null),BufferedImage.TYPE_INT_ARGB);
      return ret;
  }
  
  public BufferedImage toBufferedImage(Image img) {
      BufferedImage ret = new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_INT_RGB);
      Graphics2D g2 = ret.createGraphics();
      g2.drawImage(img,0,0,null);
      return ret;
  }
  
  public String saveTo(BufferedImage image,String URI) throws UtilityException {
      try {
          if(image == null)
              System.out.println("dododod");
          ImageIO.write(image, _type, new File(URI));
      } catch (IOException e) {
          throw new UtilityException(e.getLocalizedMessage());
      }
      return URI;
  }
  </code></pre>
  
  <p>But as an result I just get a black picture. It must have to do with the rescaling as when I skip it I can save the expected picture.</p>