Ive been struggling to figure out how to convert an image into a form of data that can be set over a network and then re-converted back into a image format for use in games.
Is it possible to even do this and how? As the imageData:getString() makes sense for this purpose but I see no way of converting the string back into an image...
transferring Images using lua-Enet.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- ArchAngel075
- Party member
- Posts: 319
- Joined: Mon Jun 24, 2013 5:16 am
Re: transferring Images using lua-Enet.
Do this to the string: https://love2d.org/wiki/love.filesystem.newFileData
Then this to the filedata: https://love2d.org/wiki/love.image.newImageData
Then this to the filedata: https://love2d.org/wiki/love.image.newImageData
- ArchAngel075
- Party member
- Posts: 319
- Joined: Mon Jun 24, 2013 5:16 am
Re: transferring Images using lua-Enet.
Attempted it with :markgo wrote:Do this to the string: https://love2d.org/wiki/love.filesystem.newFileData
Then this to the filedata: https://love2d.org/wiki/love.image.newImageData
Code: Select all
function love.load()
someImageData = love.image.newImageData("world.png")
imageDataString = someImageData:getString()
FileData = love.filesystem.newFileData( imageDataString, "world.png")
nextImageData = love.image.newImageData(FileData)
newImage = love.graphics.newImage( nextImageData )
end
function love.draw()
lg.draw(newImage,1,1)
end
Main.lua : 10
Could not decode image!
line 10 is : nextImageData = love.image.newImageData(FileData)
Re: transferring Images using lua-Enet.
Oh sorry. I was just guessing. Hopefully a dev will chime in.
Edit: Why not load the image as a string and send it? You can also save your imagedata and load it as a string.
Edit: Why not load the image as a string and send it? You can also save your imagedata and load it as a string.
- ArchAngel075
- Party member
- Posts: 319
- Joined: Mon Jun 24, 2013 5:16 am
Re: transferring Images using lua-Enet.
How exactly do you mean?
Im using a json encoder to package whatever i send accross my network.
Also im more keen on getting an image/sound file loaded, converted to string, then back to a image/sound file ready to be used... Since the string step lets me send it over networks without worrying about json complaining about userdata.
Im using a json encoder to package whatever i send accross my network.
Also im more keen on getting an image/sound file loaded, converted to string, then back to a image/sound file ready to be used... Since the string step lets me send it over networks without worrying about json complaining about userdata.
Re: transferring Images using lua-Enet.
Try this: https://love2d.org/wiki/love.filesystem.read
You can have your image in raw data. Just send the string and do filedata -> imagedata. Like I said, you can also save your imagedata to a temporary file and reload it as a string.
You can have your image in raw data. Just send the string and do filedata -> imagedata. Like I said, you can also save your imagedata to a temporary file and reload it as a string.
- ArchAngel075
- Party member
- Posts: 319
- Joined: Mon Jun 24, 2013 5:16 am
Re: transferring Images using lua-Enet.
Success!
That does indeed work, thank you good sir
Now i can also port to sound files and thus continue work on me InsanityEngine
That does indeed work, thank you good sir
Now i can also port to sound files and thus continue work on me InsanityEngine
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: transferring Images using lua-Enet.
The problem you were experiencing with getString is that it returns raw image data, not encoded into any graphics format, so when you later try to load that as png it fails.
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: transferring Images using lua-Enet.
Um could anyone explain how to do this
Who is online
Users browsing this forum: Amazon [Bot] and 89 guests