Page 2 of 2

Re: saving a canvas as an image

Posted: Thu May 09, 2019 5:52 pm
by grump
dj--alex@ya.ru wrote: Thu May 09, 2019 5:35 pm i don't like ideology with "my documents" folder. good old games always do save in their folders.
Good old games did it this way because they're old, they were played on single-user systems, and filesystem permissions did not exist. Today, any user data is expected to be saved in the user's home directory, so that it works for multiple users without conflicts or permission issues. A properly configured system will not allow users to write in application directories, so your solution does not work everywhere and will break sooner or later due to permission conflicts, or it has to be started with administrator privileges all the time. Players may even lose data when they uninstall/reinstall the game. You're shooting yourself in the foot for no good reason.

Re: saving a canvas as an image

Posted: Thu May 09, 2019 6:23 pm
by zorg
grump: Sure sounds like OS-es coddling the users to me, the single user on my own computer. What's next? Removing any way of allowing users to even access the filesystem via file managers, ls in terminals or dir in cmd/powershell? Just trust the OS managing your storage devices and install/save stuff wherever it feels like? :v but i digress. This is discord tier debate material anyway : P

Anyway,
dj--alex@ya.ru wrote: Thu May 09, 2019 5:35 pm game already save game in special folder inside GAME folder,
i just want to save image with savegame folder.
You're right, i didn't fully understand what you wanted to do, i still don't, completely... if you actually managed to make your game save into its own folder where main.lua is, and you want it to save images into there as well, just get the FileData that's returned by the :encode() method, do a :getString() on it, and finally use your method of saving into the game's folder to save your image like that; it should work.

Alternatively, you can try HDPLocust's solution, if that worked (it should, it's a lua function, but again, depending on the OS, the paths may use different separators, lack drive letters, or even not support special... let's just say non-ASCII characters.

Re: saving a canvas as an image

Posted: Thu May 09, 2019 9:05 pm
by pgimeno
Beware that the os.rename() method may not work if the destination is in a different filesystem. I'm not sure it will work for example with an SD card on Android.

Re: saving a canvas as an image

Posted: Thu May 09, 2019 9:35 pm
by dj--alex@ya.ru
i have no idea...
it just don't work and get some trash useless messages

realfilename=sourcewrite(datatowrite,levelname);
--realfilename - is correct path from savegame operator.
ImageData = GAMEWINDOWCANVAS:newImageData();
filedata = ImageData:encode( "png" );
realfilename=realfilename..".png";
if (ossys~="Android") then
local filepng = io.open(realfilename, 'wb');
if (filepng~=nil) then filepng:write(filedata); --STRING EXPECTED GOT USERDATA!!!!!!!WTF????!!!!!!!!!!!!!
filepng:close();
end;
end
if (ossys=="Android") then
love.filesystem.write(realfilename, filedata) -- for android
end;
smsg1="realfilenam="..realfilename.."";


It creates Png file with 0x0 and size 0 bytes.

Re: saving a canvas as an image

Posted: Thu May 09, 2019 10:13 pm
by zorg
dj--alex@ya.ru wrote: Thu May 09, 2019 9:35 pm it just don't work and get some trash useless messages
That message was perfectly useful; Thank you for providing code, now i can tell you that you were missing a step i did mention previously:

Code: Select all

realfilename = sourcewrite(datatowrite, levelname)
imagedata    = GAMEWINDOWCANVAS:newImageData()
filedata     = imagedata:encode( "png" )
realfilename = realfilename .. ".png"
if (ossys ~= "Android") then
	local filepng = io.open(realfilename, 'wb')
	if (filepng ~= nil) then
		filepng:write(filedata:getString()) -- <- this right here; now it's a string.
		filepng:close()
	end
else
	love.filesystem.write(realfilename, filedata) -- i have a feeling this won't work though, chief. :|
end

smsg1 = "realfilename = " .. realfilename

Re: saving a canvas as an image

Posted: Wed May 22, 2019 10:59 am
by dj--alex@ya.ru
wow! thanks i test it! it's a really long problem)
on android i use standart function.
it's really works on pc!
if it not works on android i think i can still use old command with canvas