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

Author Topic: how to get pixel color ??  (Read 9919 times)

0 Members and 1 Guest are viewing this topic.

Martinezzz

  • Newbie
  • *
  • Posts: 6
    • View Profile
how to get pixel color ??
« 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

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: how to get pixel color ??
« Reply #1 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

Martinezzz

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: how to get pixel color ??
« Reply #2 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..

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: how to get pixel color ??
« Reply #3 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
« Last Edit: September 10, 2014, 12:11:15 pm by AlexAUT »

Martinezzz

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: how to get pixel color ??
« Reply #4 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 :)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: how to get pixel color ??
« Reply #5 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. You will then have you image on which to use getPixel().
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: how to get pixel color ??
« Reply #6 on: September 12, 2014, 05:40:53 pm »
Martinezzz, the PySFML website has great API docs (python-sfml.org).

 

anything