A
A
Alexey2019-05-09 21:50:04
PNG
Alexey, 2019-05-09 21:50:04

How to correctly save canvas to png directly in Lua?

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(filename, '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.."";

My question is, is it possible to save a png image using Lua in a real path and not in the path that the love2d framework slips even if I don’t want to? love.filesystem.setIdentity('realpath');
GAMEWINDOWCANVAS:newImageData():encode('png', realpath..levelname.. 'x2.png');
Game save goes here. and this is where the picture should go.
.. /home/alex/Документы/R-M2K/M2K_GAME_FOLDER/usr/bin/saves

However (!!) instead, love2d intercepts the path value and assigns its "correct" path to it
. /home/alex/.local/share/love/home/alex/Games/M2K/usr/bin/saves/m2ksavex

as a result, in the folder with the save game. which of course is in the game folder there is no picture.
I'm told only by copying after taking a screenshot with the command above this can be fixed with os.rename(src, dst) but that looks uncivilized.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2019-05-17
@dj--alex

A working method that was suggested to me on the Internet!
realfilename = sourcewrite(datatowrite, levelname) (I'm just getting the path from my function here.)
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. this important conversion was missing.
filepng:close()
end
else
love.filesystem.write(realfilename, filedata) -- i have a feeling this won't work though, chief. :|
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question