Sign in to follow this  
Ey-Lord

Get the pixel data of an image

Recommended Posts

Ey-Lord    225
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 this post


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

Share this post


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

Share this post


Link to post
Share on other sites
yanco    126
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 :)

Share this post


Link to post
Share on other sites
lemurion    336
Quote:
Original post by Ey-Lord
thats what i was afraid of :D
i did a loop on d[i] .. 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 TESTED

unsigned 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 this post


Link to post
Share on other sites
TomasH    360
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 this post


Link to post
Share on other sites
Ey-Lord    225
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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this