How to make resized image clear and sharp
807601Jan 16 2008 — edited May 13 2009I am working on a project which reads image from an image file. such as gif or png file, then resize it and save it into another image file. After this process, the resized image appears very blur. Is there any way to make it clear and sharp?
The code is as following.
Graphics2D grph2D = null;
BufferedImage im_out=null;
/* Create output image */
im_out = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//set background color as white
grph2D = im_out.createGraphics();
grph2D.setColor(Color.white);
grph2D.fillRect(0,0,im_out.getWidth(), im_out.getHeight());
try {
InputStream is = new BufferedInputStream(new FileInputStream(GifFile)); Image im = ImageIO.read(is);
} catch (Exception ex) {
log.error("error : "+ex.getMessage());
System.exit(3);
}
if (im != null) {
grph2D.setColor(Color.black);
grph2D.drawImage( im,dX1, dY1, dX2, dY2, sX1, sY1, sX2, sY2, null);
}
//save the image into a file
BufferedOutputStream out = new BufferedOutputStream(newFileOutputStream(fname));
ImageIO.write(im_out, "png", out);
out.close();
//Free graphic resources
grph2D.dispose();