title: Quality of Image after resize very low -- Java
body: <p>In the script it is going from around the 300x300 mark down to 60x60.  Need to improve the overall image quality as it is coming out very poorly at the moment.</p>
  
  <pre><code>public static Boolean resizeImage(String sourceImg, String destImg, Integer Width, Integer Height, Integer whiteSpaceAmount) 
  {
      BufferedImage origImage;
  
      try 
      {
          origImage = ImageIO.read(new File(sourceImg));
          int type = origImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : origImage.getType();
          int fHeight = Height;
          int fWidth = Width;
          int whiteSpace = Height + whiteSpaceAmount; //Formatting all to squares so don't need two whiteSpace calcs..
          double aspectRatio;
  
          //Work out the resized dimensions
          if (origImage.getHeight() &gt; origImage.getWidth()) //If the pictures height is greater than the width then scale appropriately.
          {
              fHeight = Height; //Set the height to 60 as it is the biggest side.
  
              aspectRatio = (double)origImage.getWidth() / (double)origImage.getHeight(); //Get the aspect ratio of the picture.
              fWidth = (int)Math.round(Width * aspectRatio); //Sets the width as created via the aspect ratio.
          }
          else if (origImage.getHeight() &lt; origImage.getWidth()) //If the pictures width is greater than the height scale appropriately.
          {
              fWidth = Width; //Set the height to 60 as it is the biggest side.
  
              aspectRatio = (double)origImage.getHeight() / (double)origImage.getWidth(); //Get the aspect ratio of the picture.
              fHeight = (int)Math.round(Height * aspectRatio); //Sets the height as created via the aspect ratio.
          }
  
          int extraHeight = whiteSpace - fHeight;
          int extraWidth = whiteSpace - fWidth;
  
          BufferedImage resizedImage = new BufferedImage(whiteSpace, whiteSpace, type);
          Graphics2D g = resizedImage.createGraphics();
          g.setColor(Color.white);
          g.fillRect(0, 0, whiteSpace, whiteSpace);
  
          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);
  
          g.drawImage(origImage, extraWidth/2, extraHeight/2, fWidth, fHeight, null);
          g.dispose();
  
          ImageIO.write(resizedImage, "jpg", new File(destImg));
      } 
      catch (IOException ex) 
      {
          return false;
      }
  
      return true;
  }
  </code></pre>
  
  <p>Really just need to know if their is something I can plug in that will bump up the quality or if I need to look at something else entirely.</p>
  
  <p>EDIT: Picture comparison.</p>
  
  <p>Source, just picked a random washing machine from google.
  <a href="http://www.essexappliances.co.uk/images/categories/washing-machine.jpg" rel="noreferrer">http://www.essexappliances.co.uk/images/categories/washing-machine.jpg</a></p>
  
  <p><img src="https://i.stack.imgur.com/xKZsO.jpg" alt="Washing Machine"></p>
  
  <p>The same picture converted in Photoshop to what I need it to be.
  <a href="https://imgur.com/78B1p" rel="noreferrer">http://imgur.com/78B1p</a></p>
  
  <p><img src="https://i.stack.imgur.com/TRKij.jpg" alt="Good resize in Paint shop"></p>
  
  <p>What it looks like being converted like this.
  <a href="https://imgur.com/8WlXD" rel="noreferrer">http://imgur.com/8WlXD</a></p>
  
  <p><img src="https://i.stack.imgur.com/wkD8O.jpg" alt="Bad resize"></p>