display.colorSample()

Type Function
Library display.*
Return value none
Revision Release 2022.3683
Keywords color, sampling, screen

Overview

Get the color of a pixel on screen.

Syntax

display.colorSample( x, y, listener )
x (required)

Number. The x coordinate of the pixel on screen, in content coordinates.

y (required)

Number. The y coordinate of the pixel on screen, in content coordinates.

listener (required)

Listener. The event listener to receive the result.

Gotchas

display.colorSample() has similar performance limitations as display.capture(). This function should not be called in a tight loop, during a Runtime "enterFrame" listener, or during a touch listener's "moved" phase.

Example

local function onColorSample( 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

display.colorSample( 17, 9, onColorSample )