[SOLVED] Loading image from absolute directory using IO.Open
Posted: Fri Oct 14, 2016 8:29 pm
Hey, I'm trying to load an image into my level editor from an absolute file path. Right now i have it working with a relative spritepath but I need to have two identical "Graphics" folders, one for the game and one for the editor. (I don't want one of them under the folder of the other)
This is my code to load the file that I found online and tried to use for my project:
function LoadSprite (aSpritePath, aObjectName)
local file = assert(io.open(aSpritePath, "r"))
local filedata, err = love.filesystem.newFileData(file:read("*all"), aObjectName .. ".png")
file:close()
local image
if (err == nil) then
local imageData = love.image.newImageData(filedata)
image = love.graphics.newImage(imageData)
end
return image
end
I get this error: Could not decode file '<myImageName>.png' to ImageData: unsupported file format.
I've tried to search online, but I can't really find much about this.
Would be awesome if anyone could help me
This is my code to load the file that I found online and tried to use for my project:
function LoadSprite (aSpritePath, aObjectName)
local file = assert(io.open(aSpritePath, "r"))
local filedata, err = love.filesystem.newFileData(file:read("*all"), aObjectName .. ".png")
file:close()
local image
if (err == nil) then
local imageData = love.image.newImageData(filedata)
image = love.graphics.newImage(imageData)
end
return image
end
I get this error: Could not decode file '<myImageName>.png' to ImageData: unsupported file format.
I've tried to search online, but I can't really find much about this.
Would be awesome if anyone could help me