Read Slick2D image as a pixel array?

I’d like to convert a org.newdawn.slick.Image to an array of pixel and read its RGB. I understand there’s getColor(x,y) but wouldn’t that be awfully slow?
I wrote this code, but I don’t know how to get RGB or even if this works as intended.


public byte[] getImagePixels(Image img) {
    return img.getTexture().getTextureData();
}

Another solution would be to convert img to a BufferedImage, but it seems impossible AFAIK.

Any help?

GetColor() uses getTextureData internally with additional handling regarding wrapping, offsets, and alpha checks, so it will be slower. Use it if you need those checks.

Converting to a BufferedImage won’t save you anything, it’ll cost you. You’d still have to get out the data using the Slick API to put it in to the BufferedImage, and even then I’m not sure it’d provide any faster get* methods than the above anyway.

Ty for answer

Word of warning if you use .getColor() in a forloop for more than a dozen or so executions you’ll need to (should) run .flushPixelData() or you’ll quickly find yourself running out of memory.