imagedata:getPixel(x,y) is nil?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
jalamaya
Prole
Posts: 21
Joined: Wed Jan 13, 2016 9:14 pm

imagedata:getPixel(x,y) is nil?

Post by jalamaya »

i am attempting to get the color of the pixel at a certain position of the image i have

Code: Select all

mainImage=love.graphics.newImage('test.png')
r,g,b,a=mainImage:getPixel( 20,20 )
then i will get the error message of:
main.lua._: attempt to call method 'getPixel' (a nil value)

pls help
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: imagedata:getPixel(x,y) is nil?

Post by Kingdaro »

You need to use image.getImageData, not graphics.getImage. You can create a drawable Image from the ImageData.

Code: Select all

mainImageData = love.image.newImageData('test.png')
mainImage = love.graphics.newImage(mainImageData)

r,g,b,a = mainImageData:getPixel(20, 20)
Last edited by Kingdaro on Wed Jan 20, 2016 2:22 am, edited 1 time in total.
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: imagedata:getPixel(x,y) is nil?

Post by HugoBDesigner »

Actually, the correct function is [wiki]love.image.newImageData[/wiki], but other than that Kingdaro is completely right.
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: imagedata:getPixel(x,y) is nil?

Post by Kingdaro »

Ah, right. My mistake. I make that mistake all the time. :P
jalamaya
Prole
Posts: 21
Joined: Wed Jan 13, 2016 9:14 pm

Re: imagedata:getPixel(x,y) is nil?

Post by jalamaya »

Kingdaro wrote:You need to use image.getImageData, not graphics.getImage. You can create a drawable Image from the ImageData.

Code: Select all

mainImageData = love.image.newImageData('test.png')
mainImage = love.graphics.newImage(mainImageData)

r,g,b,a = mainImageData:getPixel(20, 20)
Thanks! So imageData is actually different from image. Thank you very much!
Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests