Get the pixel data of an image

Started by
5 comments, last by Ey-Lord 18 years, 10 months ago
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
Advertisement
Hi,
If your pointer point to an array you can get the data like this:
d[IndexNumber]
bye
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
Hi,
i don't know how exactly your loader works, but according to your loading routine
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 :)
You were born an ORIGINAL don't die a COPY...ASCENT SYSTEMS
Quote:Original post by Ey-Lord
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


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

Matt
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.)
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 :)

This topic is closed to new replies.

Advertisement