# Get the pixel data of an image

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

## Recommended Posts

hello guys ! Im using devIL to load my images ; i wonder how can i get the pixels data of the img i just loaded . i can get a ptr to data like this :
unsigned char  * d = ilGetData();

but after that, i dont understand how i can parse it and print the value ( r g b a ) for each pixels ... Thx

##### Share on other sites
Hi,
If your pointer point to an array you can get the data like this:
d[IndexNumber]
bye

##### Share on other sites
thats what i was afraid of :D
i did a loop on d .. i jsut printed some weird carater ( not ANY number btewwen 0 - 255 ) ... so im kinda lost .
ty anyway

##### Share on other sites
Hi,
unsigned char * d = ilGetData(); you're loading bytes of data. So the image should be stored as R-component d[0] G-component d[1] B-component d[2] and if the image has also alpha values a-componet woould be d[3], and so on. But it's really just a guess because you didn't say what kind of image are you loading.

Thats because when you print it, its being treated as a character. Chars are numbers try to convert it to int if you want to "see" it as a number..
Hope this helps a little :)

##### Share on other sites
Quote:
 Original post by Ey-Lordthats what i was afraid of :Di did a loop on d .. i jsut printed some weird carater ( not ANY number btewwen 0 - 255 ) ... so im kinda lost .ty anyway

you're getting weird characters because the ascci character corresponding to the number you get gets printed. Try something like this:
// THIS IS NOT TESTEDunsigned char  * d = ilGetData();printf("R: %d, R: %d, G: %d\n", d[0], d[1], d[2]);

this way you should get numbers instead of weird characters.

hope that helps
Matt

##### Share on other sites
Also, check the documentation of DevIL. There should be some way to get the format of the image data (which would tell you how to interpret the data in the array.)

##### Share on other sites
Hehe thx , i forgot i had number over 10 ... so no char is correct for that :)
a simple cast to (int) do the trick , thx :)

• 10
• 18
• 14
• 18
• 15