transferring Images using lua-Enet.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

transferring Images using lua-Enet.

Post by ArchAngel075 »

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...
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 1:45 am, edited 3 times in total.
User avatar
markgo
Party member
Posts: 190
Joined: Sat Jan 05, 2013 12:21 am
Location: USA

Re: transferring Images using lua-Enet.

Post by markgo »

User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: transferring Images using lua-Enet.

Post by ArchAngel075 »

Attempted it with :

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
Got error :
Main.lua : 10
Could not decode image!

line 10 is : nextImageData = love.image.newImageData(FileData)
User avatar
markgo
Party member
Posts: 190
Joined: Sat Jan 05, 2013 12:21 am
Location: USA

Re: transferring Images using lua-Enet.

Post by markgo »

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.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: transferring Images using lua-Enet.

Post by ArchAngel075 »

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.
User avatar
markgo
Party member
Posts: 190
Joined: Sat Jan 05, 2013 12:21 am
Location: USA

Re: transferring Images using lua-Enet.

Post by markgo »

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.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: transferring Images using lua-Enet.

Post by ArchAngel075 »

Success!
That does indeed work, thank you good sir :)

Now i can also port to sound files and thus continue work on me InsanityEngine :P
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: transferring Images using lua-Enet.

Post by bartbes »

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.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: transferring Images using lua-Enet.

Post by bobbyjones »

Um could anyone explain how to do this
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 89 guests