Jump to content
  • Advertisement
Sign in to follow this  
Ey-Lord

Get the pixel data of an image

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

If you intended to correct an error in the post then please contact us.

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


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


Link to post
Share on other sites
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
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 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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!