Created
September 26, 2010 19:33
-
-
Save nicolasH/598255 to your computer and use it in GitHub Desktop.
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 characters
//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 ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment