How to access rgb data of an image


I’d like to load up a png file and access the data of its pixels through an index. Is there a way for me to do that?


I haven’t tried to do it myself yet, but from the docs it looks like you’d make a PixelData object of the correct size, copy the texture to it, then read from that. Something like:

// given a texture named tex
auto pixData = PixelData::create(WIDTH, HEIGHT, DEPTH, FORMAT);
// Reading a pixel at (x,y)
auto pixel = pixData->getColorAt(x + y * width);
// Or setColorAt

From there, you’d just do a tex->writeData(pixData); again to set it (I think, again, haven’t tried any of this myself yet).

Docs of note:


Thank you for your help! However, the operation doesn’t seem to end, no matter how long I wait. Do you know what might be the cause of it? This is the code and the image. (The image is just above the code, very small 10x10)


HTexture tex = gImporter().import<Texture>("map\\test.png");
auto pixData = PixelData::create(10, 10, 8, PF_RGB8);

auto async = tex->readData(pixData);

while (!async.hasCompleted())


You need to ensure the operation is submitted to the core thread. Use gCoreThread.submitAll() after the readData call.

More information about the core thread here:


Thanks! It’s working now! :slight_smile: