Created
September 26, 2010 19:33
Revisions
-
nicolasH created this gist
Sep 26, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ //How to create a BufferedImage from a sub rectangle of another BufferedImage, a.k.a. 'clipping'. BufferedImage src = ImageIO.read(new File("SomeFile.png")); Rectangle clip = new Rectangle((src.getWidth() - 200) / 2, (src.getHeight() - 200) / 2, 200, 200); BufferedImage ret = new BufferedImage(clip.width, clip.height, image.getType()); //short but slow clip and paste : ret.getRaster().setRect(-clip.x, -clip.y, image.getData(clip)); //done !