Gets the color of a pixel at a specific position in the image.

Valid x and y values start at 0 and go up to image width and height minus 1. Non-integer values are floored.

In versions prior to 11.0, color component values were within the range of 0 to 255 instead of 0 to 1.

O.png Prior to 0.10.2, this function does not properly handle non-integer coordinates, and may produce an invalid result when non-integer values are passed.  



r, g, b, a = ImageData:getPixel( x, y )


number x
The position of the pixel on the x-axis.
number y
The position of the pixel on the y-axis.


number r
The red component (0-1).
number g
The green component (0-1).
number b
The blue component (0-1).
number a
The alpha component (0-1).


When the mouse is clicked, reads the red, green, and blue value of the pixel under the mouse and uses it as the background color.

local imagedata = love.image.newImageData('path/to/Image.png')
local image     =
function love.mousepressed(mx, my)
    if  0 <= mx and mx < image:getWidth()
    and 0 <= my and my < image:getHeight() then
        local r, g, b = imagedata:getPixel(mx, my), g, b)
function love.draw(), 0, 0)

See Also

Other Languages