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
Get the pixel data of an image
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 :
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
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 :)
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 :)
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
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.)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement