saving a canvas as an image

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.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

saving a canvas as an image

Post by Doctory »

Is it possible to save a canvas in a form of an image?
If so, how?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: saving a canvas as an image

Post by Nixola »

canvas:getImageData():encode(filename)
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: saving a canvas as an image

Post by Doctory »

Nixola wrote:canvas:getImageData():encode(filename)
thank you, have a nice day
dj--alex@ya.ru
Prole
Posts: 23
Joined: Sat Jun 17, 2017 1:23 pm

Re: saving a canvas as an image

Post by dj--alex@ya.ru »

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
Last edited by dj--alex@ya.ru on Sat May 04, 2019 10:06 pm, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: saving a canvas as an image

Post by pgimeno »

If you're using any version after 0.10, the function is called newImageData, not getImageData.
dj--alex@ya.ru
Prole
Posts: 23
Joined: Sat Jun 17, 2017 1:23 pm

Re: saving a canvas as an image

Post by dj--alex@ya.ru »

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
dj--alex@ya.ru
Prole
Posts: 23
Joined: Sat Jun 17, 2017 1:23 pm

Re: saving a canvas as an image

Post by dj--alex@ya.ru »

no answer.
maybe this impossible direct save file to folder with game with lua commands.
\
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: saving a canvas as an image

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
HDPLocust
Citizen
Posts: 65
Joined: Thu Feb 19, 2015 10:56 pm
Location: Swamp
Contact:

Re: saving a canvas as an image

Post by HDPLocust »

We can move encoded (saved) image file by os.rename(src, dst)
Science and violence
dj--alex@ya.ru
Prole
Posts: 23
Joined: Sat Jun 17, 2017 1:23 pm

Re: saving a canvas as an image

Post by dj--alex@ya.ru »

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"
Last edited by dj--alex@ya.ru on Thu May 09, 2019 7:01 pm, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests