BufferedImage tmp = new BufferedImage(w, h, type);
Graphics2D g2 = tmp.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(result, 0, 0, w, h, null);
g2.dispose();
result = tmp;
} while (w != targetWidth || h != targetHeight);
return result;