Game Development Community

Reading pixel colors

by Claus Havn · in Torque 2D Beginner · 03/12/2014 (5:35 pm) · 6 replies

Hello there!

Is there a method of reading the color of each individual pixel of an image?

Thank you.

About the author

Recent Threads


#1
03/13/2014 (1:16 am)
Hello Claus,

Sorry, but there is no built in method to get individual pixel colors.
#2
03/13/2014 (3:22 pm)
Thank you. Why is that?
#3
03/13/2014 (3:29 pm)
Perhaps because nothing in the engine as it currently stands needs to do that. You can access the texture data via the resource manager and get it that way, but you'll need to work with pnglib. One of the guys made a modification to the GUI system to use the alpha channel on a button's image for click detection (button only clicked if you click on visible portion of the button image) but it was lost to the sands of time....
#4
03/13/2014 (3:31 pm)
As a side note, I'm not sure if it's still there but once upon a time SceneObjects could use "visibility-based" collision (colliding based on a per-pixel comparison of the two objects' image alpha channels).
#5
03/13/2014 (4:14 pm)
I don't recall seeing that sort of code in there Richard, I would assume that got removed when Box2D was integrated.

Speaking of which, the reason pixels aren't a typical unit used in the engine comes down to the underlying physics simulation all scene objects are based on. Here is a decent answer to that:

stackoverflow.com/questions/10656588/why-shouldnt-i-use-pixels-as-unit-with-box2...

Obviously per pixel color picking has nothing to do with physics, but I guess there has never been a need for it, so no one wrote the code to support that.
#6
03/13/2014 (4:18 pm)
You are right, has nothing to do with what I need, but a good answer to why it's not there. Thank you very much.