Page 1 of 1

Getting Image Data of Image

Posted: Sat Mar 06, 2021 9:49 pm
by Drakkahn
I've been looking through the love api and I can't seem to find a way to get the ImageData from an image. I know you can replace it with (Image:replacePixels()) and you used to be able to get it with (Image:getData()). Was that feature removed, or is there just something I'm missing?

Re: Getting Image Data of Image

Posted: Sat Mar 06, 2021 10:05 pm
by GVovkiv
I guess you talking about https://love2d.org/wiki/(Image):getData

Re: Getting Image Data of Image

Posted: Sat Mar 06, 2021 10:17 pm
by steVeRoll
GVovkiv wrote: Sat Mar 06, 2021 10:05 pm I guess you talking about https://love2d.org/wiki/(Image):getData
If you read the big red warning at the top, you'll see that this function is removed since love 11.0. And like the warning suggests, there is no way to get an ImageData from an Image anymore - instead, you should first create an ImageData, and then create the Image from that, while still keeping a reference of the original ImageData around.

Re: Getting Image Data of Image

Posted: Sat Mar 06, 2021 10:21 pm
by eliddell
Or you could cheat: draw the Image to a Canvas of the same size, and use Canvas:newImageData() to get what you want. Following the wiki's recommendation is probably more efficient, though.

Re: Getting Image Data of Image

Posted: Sat Mar 06, 2021 10:28 pm
by GVovkiv
steVeRoll wrote: Sat Mar 06, 2021 10:17 pm
GVovkiv wrote: Sat Mar 06, 2021 10:05 pm I guess you talking about https://love2d.org/wiki/(Image):getData
If you read the big red warning at the top, you'll see that this function is removed since love 11.0. And like the warning suggests, there is no way to get an ImageData from an Image anymore - instead, you should first create an ImageData, and then create the Image from that, while still keeping a reference of the original ImageData around.
yeah