Results 1 to 3 of 3
Thread: Copy part of an image to another
- 04-16-2009, 08:02 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 2
- Rep Power
- 0
Copy part of an image to another
EDIT: I guess this should have been posted under the Java 2D forum. I'll repost there so this one can be deleted.
Hello,
I seem to be having some difficulty copying part of one image to another image.
BufferedImage source // 160 pixels x 224 pixels
BufferedImage dest // 16 pixels by 16 pixels
What I want to do is copy a 16x16 tile from source into dest. Lets say I want to copy tile 2,2 (pixels 32-48, 32-48)
example :
Graphics g = dest.getGraphics();
g.drawImage(source, 0, 0, 16, 16, 32, 32, 16, 16, null);
This bit of code doesn't work because it seems to try to squish the entire source image into the destination image. Then I found some code that says use Graphics.setClip():
Graphics g = dest.getGraphics();
g.setClip(32,32,16,16)
g.drawImage(source, 0, 0, null)
But that doesn't work either.
I must be missing something simple because it can't be that hard to pick out a 16 x 16 tile from an image thats 160 x 224 pixels big.Last edited by Cain; 04-16-2009 at 08:25 PM.
- 03-13-2011, 02:12 AM #2
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
Possible solution
I'm not sure how efficient this would be, but I would create another BufferedImage that is the size of the tile you want:
BufferedImage tile = new BufferedImage(16,16,BufferedImage.<whatever type>);
Then I would draw to it with an offset that would result in only the correct region being drawn:
Graphics g = tile.getGraphics();
g.drawImage(source,-32,-32);
tile should now contain the region you're looking for.
- 03-13-2011, 04:34 AM #3
Similar Threads
-
Object copy
By Oktam in forum New To JavaReplies: 6Last Post: 07-21-2010, 08:09 AM -
Attachment referencing image part
By jissondennis in forum Advanced JavaReplies: 0Last Post: 03-16-2009, 06:56 AM -
USB Device Copy
By Mir in forum New To JavaReplies: 3Last Post: 08-25-2008, 11:44 AM -
Converting multiple banded image into single banded image... Image enhancement
By archanajathan in forum Advanced JavaReplies: 0Last Post: 01-08-2008, 05:29 PM -
copy image/imageicon into a file on disk
By archanajathan in forum Advanced JavaReplies: 2Last Post: 11-22-2007, 06:21 AM


LinkBack URL
About LinkBacks

Bookmarks