This site requires JavaScript, please enable it in your browser!
Greenfoot back
ironphoenix20
ironphoenix20 wrote ...

2017/5/6

Pixel Color Change

ironphoenix20 ironphoenix20

2017/5/6

#
Hi. Is there any way for me to get the RGB values of a pixel based on where a user clicks on the image? By the way, I am trying to get the RGB values of that pixel and then change all the pixels on that image that have the same RGB values to a different color? So the user can change one color to another on the image. Please provide code or any help would be useful. Thanks
danpost danpost

2017/5/6

#
If the image is the background of the world, then you can use the 'getColorAt' method on the background image with the x and y of the mouse click. If the image is set to an actor, then you need to use the location and size of the image of the actor along with the x and y of the mouse click.
ironphoenix20 ironphoenix20

2017/5/6

#
My image is an actor so how do I get the x and y of my mouseClick. Would that be the same as the x and y of the pixel?
danpost danpost

2017/5/6

#
ironphoenix20 wrote...
My image is an actor so how do I get the x and y of my mouseClick. Would that be the same as the x and y of the pixel?
That would certainly not be the same (unless the top-left corner of the image of the actor was at the top-left corner of the world window). The location of the actor, (x, y), would be the center point of its image. So (x-getImage().getWidth()/2, y-getImage().getHeight()/2) would be the world coorindate of the top-left corner of the actor's image. Subtracting that from the point the mouse was clicked at would produce the (x, y) of the image where the mouse was clicked.
You need to login to post a reply.