Jump to content
  • Advertisement
Sign in to follow this  
Cakey

[java] [SOLVED]BufferedImage array to new BufferedImage?

This topic is 3530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
I'd also like to note, this getSubimage only works accurately with .gif files. Hopefully that saves someone a half hour on google.

Share this post


Link to post
Share on other sites
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 0x00000000
System.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.

Share this post


Link to post
Share on other sites
Thanks for that Glass Knife!

I will most likely be using a similar code to what you've provided in later development.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!