Image resize : Java

Posted by Jagadeesh VP | Posted in ,

Here is the code to resize an Image


private BufferedImage resizeImage(File imageFile) {
int width = 250;
int height = 250;

BufferedImage image = null;
try {
image = ImageIO.read(imageFile);
} catch (IOException e) {

}

BufferedImage resizedImage = new BufferedImage(width, height, image.getType());
Graphics2D g = resizedImage.createGraphics();
g.drawImage(image, 0, 0, width, height, null);
g.dispose();
return resizedImage;
}


To write an image as file

ImageIO.write(image, extension, file);

image --> RenderedImage; My case this is BufferedImage
extension --> file type
file --> your output file object

Comments (0)

Post a Comment