How to open the Photos Directory on IPad

Hello,

Upon click, I want to to open the Photos Directory/Gallery of my IPad and be able to select an image from there and display it on screen. How can I do that?

So far I haven’t been able to find any method that would open a directory on the IPad.

Thanks [import]uid: 175611 topic_id: 34232 reply_id: 334232[/import]

Look at this: http://developer.coronalabs.com/reference/index/mediashow

The following code should open the gallery, let you pick an image, and then display it in the center of the screen.

[code]local function onComplete(event)
local photo = event.target
photo.x = (display.contentWidth * 0.5)
photo.y = (display.contentHeight * 0.5)
end

media.show(media.PhotoLibrary, onComplete)[/code] [import]uid: 12217 topic_id: 34232 reply_id: 136113[/import]

Got it, thanks a lot.

One more question, in the simulator I save these photos in the Documents Directory, succesfully.

Where do these images get saved on the IPad? I’m running the App on IPad, it’s working fine but I can’t find the location where these images are saved.

Thanks [import]uid: 175611 topic_id: 34232 reply_id: 136116[/import]

You can tell media.show() the base directory where to save them and as such you can save them to system.DocumentsDirectory, system.TemporaryDirectory and system.CachesDirectory are valid choices.

[code]
local onComplete = function(event)
local photo = event.target
print( "photo w,h = " … photo.width … “,” … photo.height )
end

local outputFile = { baseDir=system.DocumentsDirectory, filename=“myfile.jpg”, type=“image” }

if media.hasSource( media.Camera ) then
media.show( media.Camera, onComplete, outputFile )
else
native.showAlert( “Corona”, “This device does not have a camera.”, { “OK” } )
end
[/code] [import]uid: 199310 topic_id: 34232 reply_id: 136121[/import]

Thank you.

My second question still stands. In the simulator my images are saved in the Systems.DocumentsDirectory. Where are these images saved on the IPad?

Plus, Where can i get more detail about system.CachesDirectory.

http://docs.coronalabs.com/api/library/system/CachesDirectory.html
this page does not have enough information. [import]uid: 175611 topic_id: 34232 reply_id: 136333[/import]

All apps are sandboxed and the directories discussed above are within the app bundle itself, and not accessible from any other apps on the device.
Some more info about the directory structure of an app can be found here (Official Apple docs):
http://tinyurl.com/brzn3po

On the iPad only your app can access files in the app’s Documents directory (which is why you can’t find them anywhere).
If you want to see your images in the Photos app you can use media.save()
[import]uid: 70847 topic_id: 34232 reply_id: 136338[/import]

Alright, that’s a clear answer. Thanks a lot.

I have another question now, using media.save(), the pictures are being saved as picture1, picture 2 etc. while i want the pictures to be saved with date and time stamp. does media.save allow setting picture name manually?

Thanks. [import]uid: 175611 topic_id: 34232 reply_id: 136339[/import]

Unfortunately, I don’t think so… :frowning:
[import]uid: 70847 topic_id: 34232 reply_id: 136340[/import]

According to this page it is possible to set the filename manually: http://docs.coronalabs.com/api/library/media/save.html

Try something like this for the time stamp:

[code]local date = os.date(’*t’)

local filename = myPictureName…"_"…date.day…"_"…date.month…"_"…date.year…".jpg"

media.save(filename)
[/code]

More on os.date can be found here: http://docs.coronalabs.com/api/library/os/date.html [import]uid: 12217 topic_id: 34232 reply_id: 136341[/import]

Yeah, but that’s the name of the file in the Documents directory (or other base directory if specified) that you want to “transfer” to the Photo Library.

You can’t control what the name of the image will be in the Photos app AFAIK… [import]uid: 70847 topic_id: 34232 reply_id: 136342[/import]

Oh, I see. Thanks for the correction! [import]uid: 12217 topic_id: 34232 reply_id: 136349[/import]

Look at this: http://developer.coronalabs.com/reference/index/mediashow

The following code should open the gallery, let you pick an image, and then display it in the center of the screen.

[code]local function onComplete(event)
local photo = event.target
photo.x = (display.contentWidth * 0.5)
photo.y = (display.contentHeight * 0.5)
end

media.show(media.PhotoLibrary, onComplete)[/code] [import]uid: 12217 topic_id: 34232 reply_id: 136113[/import]

Got it, thanks a lot.

One more question, in the simulator I save these photos in the Documents Directory, succesfully.

Where do these images get saved on the IPad? I’m running the App on IPad, it’s working fine but I can’t find the location where these images are saved.

Thanks [import]uid: 175611 topic_id: 34232 reply_id: 136116[/import]

You can tell media.show() the base directory where to save them and as such you can save them to system.DocumentsDirectory, system.TemporaryDirectory and system.CachesDirectory are valid choices.

[code]
local onComplete = function(event)
local photo = event.target
print( "photo w,h = " … photo.width … “,” … photo.height )
end

local outputFile = { baseDir=system.DocumentsDirectory, filename=“myfile.jpg”, type=“image” }

if media.hasSource( media.Camera ) then
media.show( media.Camera, onComplete, outputFile )
else
native.showAlert( “Corona”, “This device does not have a camera.”, { “OK” } )
end
[/code] [import]uid: 199310 topic_id: 34232 reply_id: 136121[/import]

Thank you.

My second question still stands. In the simulator my images are saved in the Systems.DocumentsDirectory. Where are these images saved on the IPad?

Plus, Where can i get more detail about system.CachesDirectory.

http://docs.coronalabs.com/api/library/system/CachesDirectory.html
this page does not have enough information. [import]uid: 175611 topic_id: 34232 reply_id: 136333[/import]

All apps are sandboxed and the directories discussed above are within the app bundle itself, and not accessible from any other apps on the device.
Some more info about the directory structure of an app can be found here (Official Apple docs):
http://tinyurl.com/brzn3po

On the iPad only your app can access files in the app’s Documents directory (which is why you can’t find them anywhere).
If you want to see your images in the Photos app you can use media.save()
[import]uid: 70847 topic_id: 34232 reply_id: 136338[/import]

Alright, that’s a clear answer. Thanks a lot.

I have another question now, using media.save(), the pictures are being saved as picture1, picture 2 etc. while i want the pictures to be saved with date and time stamp. does media.save allow setting picture name manually?

Thanks. [import]uid: 175611 topic_id: 34232 reply_id: 136339[/import]

Unfortunately, I don’t think so… :frowning:
[import]uid: 70847 topic_id: 34232 reply_id: 136340[/import]

According to this page it is possible to set the filename manually: http://docs.coronalabs.com/api/library/media/save.html

Try something like this for the time stamp:

[code]local date = os.date(’*t’)

local filename = myPictureName…"_"…date.day…"_"…date.month…"_"…date.year…".jpg"

media.save(filename)
[/code]

More on os.date can be found here: http://docs.coronalabs.com/api/library/os/date.html [import]uid: 12217 topic_id: 34232 reply_id: 136341[/import]

Yeah, but that’s the name of the file in the Documents directory (or other base directory if specified) that you want to “transfer” to the Photo Library.

You can’t control what the name of the image will be in the Photos app AFAIK… [import]uid: 70847 topic_id: 34232 reply_id: 136342[/import]