LWJGL
May 22, 2012, 03:14:58 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.8.3 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Saving to and Loading from memory  (Read 2883 times)
pkmnfrk
Newbie
*
Posts: 1


« on: February 26, 2008, 12:38:53 »

Hi, I just started using this library, and it seems pretty neat. However, I'm having a problem:

Code:
public Bitmap getChunk(int x, int y, int w, int h) {

IL.ilBindImage(ilHandle);

//Construct a new bitmap
Bitmap bmp = new Bitmap(w,h);

//copy the pixel data
IL.ilCopyPixels(x,y,0,w,h,1,IL.IL_RGBA,IL.IL_UNSIGNED_BYTE,bmp.imageData);

//load it into the copy's image
IL.ilBindImage(bmp.ilHandle);
IL.ilLoadL(IL.IL_RGBA, bmp.imageData);

//try to save it, in a futile attempt at debugging
if(!IL.ilSaveImage("./test" + bmp.ilHandle + ".png")) {
System.out.println("Error: " + IL.ilGetError());
}

//win
return bmp;
}

A bit of explanation: My Bitmap class keeps both the DevIL handle and a copy of the image data (both of which are allocated in the constructor). This method is part of the Bitmap class, allowing one to extract a sub-bitmap (say, a sprite from a sprite sheet).

I've confirmed that when I call this method, the Bitmap has a valid image in DevIL. I can save the original to a file just fine. And, I painstakingly checked the bmp.imageData buffer, and that is being written. But, when I copy it to the new image (just after ilCopyPixels), it doesn't load. And, when I save it (for debugging purposes), it's just a blank white pixel.

Oh, here's the constructor, if it's important:

Code:
public Bitmap(int w, int h) {
imageData = BufferUtils.createByteBuffer(w * h * 4 + 8);
width = w;
height = h;

ilHandle = ImageLoader.createImageHandle();
}

I am at a loss as to what to do...
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!