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

Author Topic: PixelPicking with sf::Image  (Read 1108 times)

0 Members and 1 Guest are viewing this topic.

bszandras

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
PixelPicking with sf::Image
« on: May 21, 2020, 09:28:51 am »
I am pretty sure I am missing something, but I have been Google-ing this for the last week.
My problem is, that the underneath can not find any pixels Blue (0, 0, 255), and I have absolutely no idea why it is not working. :(

Little explanation:
startingCave is the name of the Image
what I am trying to achive, is that with the two for loops, the code should go through the image row by row and everytime it finds a blue pixel it should set the if statement true


        Vector2f globalCurrentPos;
        sf::Color pixelColor;

        for (int y = 0; y < startingCave.getSize().y; y++) {
                for (int x = 0; x < startingCave.getSize().x; x++) {

                        globalCurrentPos.x = originDirt.x + x ;
                        globalCurrentPos.y = originDirt.y + y ;

                        pixelColor == startingCave.getPixel(x, y);
                        if (pixelColor == sf::Color(0, 0, 255)) {
                                //createDirt(world, globalCurrentPos);

                                debugText.setString("found");
                        }
                }
        }
« Last Edit: May 21, 2020, 09:42:52 am by bszandras »

bszandras

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: PixelPicking with sf::Image
« Reply #1 on: May 21, 2020, 11:27:01 am »
Figured it out!

In case someone, a beginner like me does not know, the "==" operator does not set a color in sf::Color, it compares colors, so my attempt, to set the variable "pixelColor" as the color of the current pixel the loop is looking at failed allways.

Athenian Hoplite

  • Newbie
  • *
  • Posts: 19
  • Nenikikamen !
    • View Profile
Re: PixelPicking with sf::Image
« Reply #2 on: May 21, 2020, 01:25:54 pm »
.. the "==" operator does not set a color in sf::Color, it compares colors ...

The "==" operator never sets anything. It is always used to do comparisons, when valid, returning a boolean.
"By will of the Athenian People be it resolved:
If anyone rises up against the people for tyranny or join in establishing the tyranny or overthrow the People of the Athenians and the democracy in Athens, whoever kills him who does these things shall be blameless." - Athenian Law 337 BC

 

anything