Page 1 of 2

saving a canvas as an image

Posted: Sat Oct 11, 2014 1:35 pm
by Doctory
Is it possible to save a canvas in a form of an image?
If so, how?

Re: saving a canvas as an image

Posted: Sat Oct 11, 2014 2:15 pm
by Nixola
canvas:getImageData():encode(filename)

Re: saving a canvas as an image

Posted: Sat Oct 11, 2014 2:19 pm
by Doctory
Nixola wrote:canvas:getImageData():encode(filename)
thank you, have a nice day

Re: saving a canvas as an image

Posted: Sat May 04, 2019 9:48 pm
I can save image to "1.png" like this?
canvas need to change name used canvas?

GAMEWINDOWCANVAS:getImageData():encode(filename)

ERROR!! attempt to call a nil value

i have canvas with gamefield named GAMEWINDOWCANVAS
how to save it using this command ?

i trying just canvas like in a original but it doesn't work

canvas of course exists and works

Re: saving a canvas as an image

Posted: Sat May 04, 2019 10:05 pm
by pgimeno
If you're using any version after 0.10, the function is called newImageData, not getImageData.

Re: saving a canvas as an image

Posted: Sat May 04, 2019 10:07 pm
love.filesystem.setIdentity('realpath');
GAMEWINDOWCANVAS:newImageData():encode('png', realpath..levelname.. 'x2.png');


Thanks but
why it ignore realpath if i add it to filename?
realpath interpreted incorrect
/home/alex/.local/share/love/home/alex/Games/M2K/usr/bin/saves/m2ksavex

Im use 0.10.2 but Android packager limits me to 0.10.2 for forever.


i need to save files here
/home/alex/Документы/R-M2K/M2K_GAME_FOLDER/usr/bin/saves
image with savemage MUST be with folder with savegame...

and i get canvas image here
/home/alex/.local/share/love/m2k

Re: saving a canvas as an image

Posted: Wed May 08, 2019 8:20 pm
no answer.
maybe this impossible direct save file to folder with game with lua commands.
\

Re: saving a canvas as an image

Posted: Wed May 08, 2019 9:18 pm
by zorg
Apart from the necro-posting you performed previously, yes, the encode function can only save to the save folder like literally all other löve related functions.

Also, forget about the realpath, you don't need to use it, it's already relative to the save folder.

GAMEWINDOWCANVAS:newImageData():encode('png', levelname.. 'x2.png')

That should do what you want... but then again, it's android, it may just not work at all.

Re: saving a canvas as an image

Posted: Thu May 09, 2019 6:01 am
by HDPLocust
We can move encoded (saved) image file by os.rename(src, dst)

Re: saving a canvas as an image

Posted: Thu May 09, 2019 5:35 pm
to zorg
you don't understang
game already save game in special folder inside GAME folder,
i just want to save image with savegame folder.
i don't like ideology with "my documents" folder. good old games always do save in their folders.

to HDPLocust
for save game i use
file=love.filesystem.write(realfilename, data)
and it always works.


copy image from screenshot "zone" to destination - really no another methods?
i still hope, maybe found normal command like
canvas:saveimage(realpath,".png)...
i just need get png and redirect it as "data"