I'm making an UI for an application (a launcher for a few utilities) and I need to show a few images on screen, which are located on a different path than my löve project. There's no option to include them in the project directory, at least for now. Each part of the project is located on different partitions in a Rockchip board.
These would be the paths:
-Love project: /ui
-Png files: /assets/png
I have this variable:
local externalPngDir = /assets/png/
As expected, when I use love.graphics.newImage(externalPngDir .. externalPngFile), I get an error.
Would there be a way for this to work or should I ask my teammates to change the project directories structure?
Using love.graphics.newImage() with png files in an external directory
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Using love.graphics.newImage() with png files in an external directory
I use a helper function like this in such situations
Code: Select all
local function loadImageFromPath( filePath )
local f = io.open( filePath, "rb" )
if f then
local data = f:read( "*all" )
f:close()
if data then
data = love.filesystem.newFileData( data, "tempname" )
data = love.image.newImageData( data )
local image = love.graphics.newImage( data )
return image
end
end
end
Re: Using love.graphics.newImage() with png files in an external directory
Worked like a charm. Thank you very much!
Re: Using love.graphics.newImage() with png files in an external directory
That's the easy part!
How do I save the image to the original directory after modifying?
How do I save the image to the original directory after modifying?
Re: Using love.graphics.newImage() with png files in an external directory
Same as reading, but reverse order of function calls, or save file in lovegame dir and copy/move to destination path.
Science and violence
Re: Using love.graphics.newImage() with png files in an external directory
Not if you want a jpg or png file.
You have to encode the data into the appropriate format.
There in lies the rub.
Love combines formatting and sending the image to the app folder - not to the directory of your choice.
You have to encode the data into the appropriate format.
There in lies the rub.
Love combines formatting and sending the image to the app folder - not to the directory of your choice.
Re: Using love.graphics.newImage() with png files in an external directory
Code: Select all
data = image:encode("png"):getString()
file:write(data)
Re: Using love.graphics.newImage() with png files in an external directory
Thanks grump.
Assume you mean:
Assume you mean:
Code: Select all
local data = imagedata:encode( "png" ):getString()
file:write( data )
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot], Google [Bot] and 3 guests