SFML community forums

Help => Graphics => Topic started by: Martinezzz on September 10, 2014, 11:16:48 am

Title: how to get pixel color ??
Post by: Martinezzz on September 10, 2014, 11:16:48 am
is there simple fast way to get pixel data at given position ???   aka    pcolor(x,y)


i need to read colordatta  form allredy drawn screen
Title: Re: how to get pixel color ??
Post by: AlexAUT on September 10, 2014, 11:29:15 am
It's not fast but you could render to a rendertexture then copy its content to an sf::Image (copyToImage()) and then call getPixel().



AlexAUT
Title: Re: how to get pixel color ??
Post by: Martinezzz on September 10, 2014, 11:43:31 am
i cant find actualy how to copy from renderTexture to image. in google ewery body says look in doc but there actualy nothing similar

there are functions to copy from memory from file stream etc..
Title: Re: how to get pixel color ??
Post by: AlexAUT on September 10, 2014, 11:59:32 am
Look at the doc of sf::RenderTexture: there you will find getTexture() which return a sf::Texture. Then look at the doc of sf::Texture and there you will find a function copyToImage(). And the docs of sf::Image contains getPixel()

auto image = renderTexture.getTexture().copyToImage();
auto color = image.getPixel(1,1);

AlexAUT
Title: Re: how to get pixel color ??
Post by: Martinezzz on September 10, 2014, 12:28:24 pm
Thanks. Hope this will work. I use pysfml there litl bit different names .. but i figured this out :)
Title: Re: how to get pixel color ??
Post by: Hapax on September 12, 2014, 05:16:43 pm
If speed is not an issue, it may be simpler to capture the window directly to an image (http://sfml-dev.org/documentation/2.1/classsf_1_1RenderWindow.php#a9bd8655d0bac83145bfc329ea7a6d538). You will then have you image on which to use getPixel().
Title: Re: how to get pixel color ??
Post by: Tank on September 12, 2014, 05:40:53 pm
Martinezzz, the PySFML website has great API docs (python-sfml.org).