"Learning gives Creativity,Creativity leads to Thinking,
Thinking provides Knowledge,
Knowledge makes you Great"
Saturday, 23 November 2013
Loading, cropping, saving an image in Java
Create a new BufferedImage with the desired width and height.
Get hold of it's Graphics object
Load the original .jpeg image
Paint the desired part of that, onto the BufferedImage
Write the buffered image out to file using ImageIO.
Image orig =ImageIO.read(newFile("duke.jpg"));int x =10, y =20, w =40, h =50;BufferedImage bi =newBufferedImage(w, h,BufferedImage.TYPE_INT_ARGB);
bi.getGraphics().drawImage(orig,0,0, w, h, x, y, x + w, y + h,null);ImageIO.write(bi,"png",newFile("duke_cropped.png"));