Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::image::GetPixel  (Read 6641 times)

0 Members and 1 Guest are viewing this topic.

Question_Dude

  • Newbie
  • *
  • Posts: 2
    • View Profile
sf::image::GetPixel
« on: February 07, 2010, 04:22:30 am »
Hello. I just started messing with SFML for fun, i found something strange when trying to get colors per pixels, maybe (probably) i'm using something wrong, but still, here's what i'm getting:



Code: [Select]

img_Width = myImage.GetWidth ( );
img_Height = myImage.GetHeight ( );

for ( Uint32 i = 0; i != img_Width; ++i ) {
for ( Uint32 j = 0; j != img_Height; ++j ) {
const sf::Color color = myImage.GetPixel ( i, j );
std::cout << "Color of Pixel [i] x [j] \n";
std::cout << "Red = " << color.r;
std::cout << " Green = " << color.g;
std::cout << " Blue = " << color.b << std::endl;

}
}

testSprite.SetImage ( myImage );
}


i don't get why every GetPixel are returning an empty sf::Color, it's showing well on the window (it's the blue square with green border)

DdR_Dan

  • Newbie
  • *
  • Posts: 9
    • View Profile
sf::image::GetPixel
« Reply #1 on: February 07, 2010, 09:06:23 am »
Try changing "<< color.r" to "<<(int)color.r".  That seemed to work for me.
Triple Beat!

Triple Beat RPG+simultaneous rhythm game:

Question_Dude

  • Newbie
  • *
  • Posts: 2
    • View Profile
sf::image::GetPixel
« Reply #2 on: February 07, 2010, 04:48:21 pm »
worked well! Thank you very much!