Page 1 of 1

Window icon cannot be changed.

Posted: Fri Jan 08, 2016 7:08 pm
by larz

Code: Select all

local data =love.image.newImageData(16,16,"icon.png");
love.window.setIcon(icon);
"icon.png" is a 16x16px image.
When i run the the program i get this error:

"main.lua:1: The size of the raw byte string must match the ImageData's actual size in bytes."

Is there something wrong on the script?

Re: Window icon cannot be changed.

Posted: Fri Jan 08, 2016 7:20 pm
by pgimeno
Check all the variants the documentation of newImageData. Note that none of the forms accepts a size followed by a filename. The closest is newImageData(filename), which doesn't need the size because it's encoded in the file itself.

Re: Window icon cannot be changed.

Posted: Fri Jan 08, 2016 7:21 pm
by bartbes
Yes, the three-argument version of newImageData accepts raw imagedata as the third argument.
In your case, you want the one-argument version, which accepts a filename.

Re: Window icon cannot be changed.

Posted: Fri Jan 08, 2016 7:22 pm
by larz
But i need an ImageData for setting an Icon. Am i right?

Re: Window icon cannot be changed.

Posted: Fri Jan 08, 2016 7:27 pm
by pgimeno
Yes.

In my first version of the post I asked if you were sure that you needed newImageData rather than newImage. Then I realized it was actually for an icon, not for drawing it yourself, so I deleted that part because for an icon, you need newImageData indeed.

Re: Window icon cannot be changed.

Posted: Fri Jan 08, 2016 7:51 pm
by larz
Ok!
How could i do that? Is there a way to convert pixels to bytes and find the dimensions?

Re: Window icon cannot be changed.

Posted: Fri Jan 08, 2016 8:11 pm
by slime
You can load an ImageData from a file like: local data = love.image.newImageData("icon.png")