   [java] [SOLVED]BufferedImage array to new BufferedImage?
  So I'm using the BufferedImage.getRGB(v,v,v,v,v,v) command to capture regions of a buffered image loaded from my hard-drive. What I need to do is find a way to turn the captured array to buffered image of it's own.Pretty much I am designing a game, and just want all the textures for multiple objects in one .bmp file for orgizational reasons.Anyone know how to turn a captured array from a bufferedimage to a buffered image again? I'm sure this is easy, and I'm just missing a command or something, but it'd be a big help if someone could help a brotha out![Edited by - Cakey on January 23, 2009 12:36:53 PM]
setRGB? It works pretty much the same way as getRGB.   ;  I don't see how that takes image data and turns it into it's own BufferedImage... Forgive my noobyness.Nevermind... public BufferedImage getSubimage(int x, int y, int w, int h)is what I needed.   ;  I'd also like to note, this getSubimage only works accurately with .gif files. Hopefully that saves someone a half hour on google.   ;  Cakey,I would suggest getting the int[] pixel values for both the source and destination BufferedImage.  That way you don't need a function call to get every single pixel.Try the following code...DataBufferInt buf = (DataBufferInt) bufferedImage.getRaster().getDataBuffer();int[] asdf = buf.getData();It is a little harder to use because you have a single array, but I think this approach would be easier and faster once you figure out how to access the rows and cols with the single array.  The BufferedImage will tell you the width and height.I have used this method for a software renderer in Java, and it works great.  When you set the values in the int[], you are setting the pixel values of the BufferedImage.  Then you just draw the BuffereImage.  This lets you do stuff like this...// clear the buffer...int[] clear = new int[ width * height ]; // initialized to 0x00000000System.arrayCopy( clear, 0, bufferedImageIntArray, 0, clear.length );This is more low level, but if you're doing custom graphics, its nice to have full control.;  Thanks for that Glass Knife!I will most likely be using a similar code to what you've provided in later development.