Saving to and Loading from memory

Started by pkmnfrk, February 26, 2008, 20:38:53

Previous topic - Next topic


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

public Bitmap getChunk(int x, int y, int w, int h) {
	//Construct a new bitmap
	Bitmap bmp = new Bitmap(w,h);
	//copy the pixel data

	//load it into the copy's image
	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());
	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:

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...