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.
-
jalamaya
- Prole
- Posts: 21
- Joined: Wed Jan 13, 2016 9:14 pm
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
-
Kingdaro
- Party member
- Posts: 395
- Joined: Sun Jul 18, 2010 3:08 am
Post
by Kingdaro »
You need to use
image.getImage
Data, 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.
-
HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
-
Contact:
Post
by HugoBDesigner »
Actually, the correct function is [wiki]love.image.newImageData[/wiki], but other than that Kingdaro is completely right.
-
Kingdaro
- Party member
- Posts: 395
- Joined: Sun Jul 18, 2010 3:08 am
Post
by Kingdaro »
Ah, right. My mistake. I make that mistake all the time.
-
jalamaya
- Prole
- Posts: 21
- Joined: Wed Jan 13, 2016 9:14 pm
Post
by jalamaya »
Kingdaro wrote:You need to use
image.getImage
Data, 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!
Users browsing this forum: No registered users and 33 guests