Answer the question
In order to leave comments, you need to log in
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.."";
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
. /home/alex/.local/share/love/home/alex/Games/M2K/usr/bin/saves/m2ksavex
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question