Introducing the “Color Sample” Function

For those Corona developers seeking a way to get the color of a specific pixel on the screen, you’re in luck! Starting with Daily Build #2106, our engineers have implemented the display.colorSample() function for this purpose. This function is an advanced graphics feature which can only be used by Pro/Enterprise subscribers.

Syntax

Using this function is simple: just provide a pixel location (in content space) and include a reference to a listener function which will receive the color values. Here’s the basic syntax:

1

display.colorSample(x,y,onColorSample)

Then, in the listener function, gather the values from the function’s event table. For example:

1

2

3

4

5

6

7

functiononColorSample(event)

print("Sampling pixel at position ("..event.x..","..event.y..")")

print("R = "..event.r)

print("G = "..event.g)

print("B = "..event.b)

print("A = "..event.a)

end

As you can see, the event table sent to the listener function contains an r, g, b, and a value for your usage, along with the sampled pixel’s x and y coordinates.

Performance Limitations

At this time, the display.colorSample() function shares similar performance limitations as display.capture(), and like that function, it shouldn’t be used in tight loops, Runtime “enterFrame” listeners, or the “moved” phase of a touch handler. However, it gives you easy access to a pixel’s color values in just a few lines of code.

Disclaimer: SDKNews.com only syndicates the blog entries from various SDK blogs.
We are not the creator/author of these entries (posts). Product names, brand names
and company names mentioned on this site may be trademarks of their respective owners.