media.selectPhoto png or jpg or ?

Hi,

With reference to media.selectPhoto

https://docs.coronalabs.com/api/library/media/selectPhoto.html

You can see an example at the bottom of the page at the link, they select a photo and that photo is saved to the syste.TemporaryDirecty…

I am looking at this line;

destination = { baseDir=system.TemporaryDirectory, filename=“image.jpg”, type=“image” }

So it looks like it is being saved as a JPG, but they could have chosen any image file - right?

They could have chosen a PNG for example. 

So…

A. Is Corona using the filename extension to set the format the file will be saved in? i.e. would Corona be doing a conversion from PNG to JPG in this instance, if the user selected a PNG?

B. Or is the filename irrelevant… in which case, how do I determine the file format of the saved file?

Hope this makes sense.

I guess I have the same question with regards to the camera capture function (are there cameras that caputre in a format other than JPG?? i don’t know)

Many thanks. 

Hey,

when I’m looking at the linked docs page, I don’t see an image beeing saved in examples. They are only selecting images.

Images can be save with media.save for example, where you specify a base path and a filename.

https://docs.coronalabs.com/api/library/media/save.html

So for your questions:

A: Yes, (of course) there are file extensions used. And no, they are not “converted” by opening them with the wrong file extension.

B: Nope

Hope that helps :slight_smile:

Images are loaded if it’s a supported version (i.e. you can’t load a .PSD file). The image is saved in the same format as the original to your sandbox folder regardless of the name you give it.

UPDATE: on iOS the file will be converted to your destination extension. On OS X it will not.

Rob

Thanks Rob, that was exactly what I was asking.

Is Corona capable of determining the format of an image file?

I think it must be doing this internally somehow, because it allows me to display an image of PNG or JPG format, regardless of the filename, as these formats are different to process, it must be detecting the format somehow.

Is there a way I can detect the format? (so I can rename the file to have the correct extension for example)

I suspect that the native API calls we are using to load a file and get an in-memory bitmap are looking at the format of the data and figuring out what kind of file it is.

Rob

Hey,

when I’m looking at the linked docs page, I don’t see an image beeing saved in examples. They are only selecting images.

Images can be save with media.save for example, where you specify a base path and a filename.

https://docs.coronalabs.com/api/library/media/save.html

So for your questions:

A: Yes, (of course) there are file extensions used. And no, they are not “converted” by opening them with the wrong file extension.

B: Nope

Hope that helps :slight_smile:

Images are loaded if it’s a supported version (i.e. you can’t load a .PSD file). The image is saved in the same format as the original to your sandbox folder regardless of the name you give it.

UPDATE: on iOS the file will be converted to your destination extension. On OS X it will not.

Rob

Thanks Rob, that was exactly what I was asking.

Is Corona capable of determining the format of an image file?

I think it must be doing this internally somehow, because it allows me to display an image of PNG or JPG format, regardless of the filename, as these formats are different to process, it must be detecting the format somehow.

Is there a way I can detect the format? (so I can rename the file to have the correct extension for example)

I suspect that the native API calls we are using to load a file and get an in-memory bitmap are looking at the format of the data and figuring out what kind of file it is.

Rob