About the API with Image Format Conversion‏

Dear Sir/Madam,

I am currently evaluating the Corona SDK to help me to develop the game application. My game application would use TCP connection with the proprietary protocol to communicate between client and server. Also, the image files (PNG/JPG) would use such connection to transfer from server to client.

Is Corona SDK supported to convert the received TCP raw bytes into PNG/JPEG data format in RAM on-the-fly? I DO NOT prefer to save the received TCP raw bytes into local directory and then read the saved data as a file object with the PNG/JPEG data format.

I look forward to hearing your response.

Yours faithfully,

Jacky

Corona SDK supports Lua sockets to do TCP/IP level socket communications to servers.  We also support HTTP through our network.request() API to do RESTful WebAPI calls.

As far as getting raw binary data and converting it to an in-memory image, this is not possible with Corona SDK.  You would have to write the data out to a file and then load the file.

Rob

Hello Rob,

Thanks for your quick reply. I would like to ask one more question. Are there any technical constraints in the Corona SDK to convert the received raw binary data into the in-memory image if I write the native plugins myself or use other existing third party plugins?

Thanks and Regards,

Jacky

Well, Corona SDK’s display objects live in OpenGL.  You could use Corona Enterprise to read that stream of data and turn it into a UIImage but there is still no way to get that to be a Corona SDK display object.  There is probably some technical way using Enterprise, but I’m not sure what it is.  I’ll ask Engineering.

Rob

I heard back from Engineering and this won’t be possible even with Enterprise.  You could make a UIImage in iOS or an Android ImageView and have it draw on top of the OpenGL canvas, but it will be like any other native object in that it’s not really part of the display engine. 

Is there a reason you are opposed to writing out a temporary file?  At least for Android and Windows 8 Phone, textures are dumped when the app suspends to free up memory and if you don’t have this as a file that can be read back in, you would have to query it from the server again which could lead to performance problems. 

Rob

Corona SDK supports Lua sockets to do TCP/IP level socket communications to servers.  We also support HTTP through our network.request() API to do RESTful WebAPI calls.

As far as getting raw binary data and converting it to an in-memory image, this is not possible with Corona SDK.  You would have to write the data out to a file and then load the file.

Rob

Hello Rob,

Thanks for your quick reply. I would like to ask one more question. Are there any technical constraints in the Corona SDK to convert the received raw binary data into the in-memory image if I write the native plugins myself or use other existing third party plugins?

Thanks and Regards,

Jacky

Well, Corona SDK’s display objects live in OpenGL.  You could use Corona Enterprise to read that stream of data and turn it into a UIImage but there is still no way to get that to be a Corona SDK display object.  There is probably some technical way using Enterprise, but I’m not sure what it is.  I’ll ask Engineering.

Rob

I heard back from Engineering and this won’t be possible even with Enterprise.  You could make a UIImage in iOS or an Android ImageView and have it draw on top of the OpenGL canvas, but it will be like any other native object in that it’s not really part of the display engine. 

Is there a reason you are opposed to writing out a temporary file?  At least for Android and Windows 8 Phone, textures are dumped when the app suspends to free up memory and if you don’t have this as a file that can be read back in, you would have to query it from the server again which could lead to performance problems. 

Rob

Are we still unable to convert a remote image to a display object without saving it a temporary file?  This is going to cause an issue for my application as I need to be able to load images 2-3+ per second but I only ever need to have 2 in memory.  how can I avoid the overhead of saving them as a temporary file?

I find it hard to believe that this cannot be done.  What is the difference in loading the image data from a local file or getting from a network request?  Once you have the bits, either way, it should be handled the same from that point on.

I also have an Enterprise license if that helps.

Thanks,

Scott

You should be able to use network.request() to download images directly to display objects.  We may still have to create a temporary file as part of the download process. 

Have you tried display.loadRemoteimage()?

https://docs.coronalabs.com/api/library/display/loadRemoteImage.html

Rob

Are we still unable to convert a remote image to a display object without saving it a temporary file?  This is going to cause an issue for my application as I need to be able to load images 2-3+ per second but I only ever need to have 2 in memory.  how can I avoid the overhead of saving them as a temporary file?

I find it hard to believe that this cannot be done.  What is the difference in loading the image data from a local file or getting from a network request?  Once you have the bits, either way, it should be handled the same from that point on.

I also have an Enterprise license if that helps.

Thanks,

Scott

You should be able to use network.request() to download images directly to display objects.  We may still have to create a temporary file as part of the download process. 

Have you tried display.loadRemoteimage()?

https://docs.coronalabs.com/api/library/display/loadRemoteImage.html

Rob