Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Save image to phone
Started by jn19 Sep 27 2011 03:16 AM

- - - - -
46 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

jn19

[GLOBAL: userInfoPane.html]
jn19
  • Contributor

  • 199 posts
  • Guests

How can we save an image to the user's phone? Say if the user is viewing a photo gallery, and they want to save one of the images into their own photo library. Is this possible with Corona?
uid: 52127 topic_id: 15661 reply_id: 315661


[TOPIC: post.html]
#2

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Currently, the only way for Corona to save an image to the photo library is via the display.captureScreen() function. Please see the following API documentation...

http://developer.anscamobile.com/reference/index/displaycapturescreen
uid: 32256 topic_id: 15661 reply_id: 57828


[TOPIC: post.html]
#3

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

I'd also really like a way to save an image that is in the app to the users photo library. I have a small app I would like to make but it requires that the user can save an image that is bigger than what can be seen on screen, so capture screen wont work for me. I guess I could link to a web site with the image but that would not be as optimal.
uid: 17969 topic_id: 15661 reply_id: 58168


[TOPIC: post.html]
#4

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

borgb,

Out of interest, where are you getting this large image from?
uid: 32256 topic_id: 15661 reply_id: 58224


[TOPIC: post.html]
#5

jn19

[GLOBAL: userInfoPane.html]
jn19
  • Contributor

  • 199 posts
  • Guests

In the documentation for display.captureScreen (http://developer.anscamobile.com/node/2467) it states this:
"Note: display.captureScreen doesn't work with most Android devices. [case #3332]"

I also saw on the release notes for build #622 this:
"Android: Added media.show() camera and photo library support. casenum: 361, 7916"

So does that mean that that this works on Android now?
uid: 52127 topic_id: 15661 reply_id: 58228


[TOPIC: post.html]
#6

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

jn19,

We used to have problems with display.captureScreen() on many Android devices, but that has been fixed. Looks like we forgot to update the documentation. Thanks for bringing that up to our attention.

And yes, we finally support the Android camera and photo library!!! This is our first revision of it on Android, so if you have any feedback about these features, then please feel free to tell us. Thanks!
uid: 32256 topic_id: 15661 reply_id: 58240


[TOPIC: post.html]
#7

jn19

[GLOBAL: userInfoPane.html]
jn19
  • Contributor

  • 199 posts
  • Guests

ok, I will try it out. What would be much more useful is if display.save() could also save to the photo library, because it is rare that what we actually need to save is a screen capture.

It seems like Ansca should be able to do this with similar code as is used to save the screen capture?
uid: 52127 topic_id: 15661 reply_id: 58263


[TOPIC: post.html]
#8

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

Joshua:
It would be for a small app where the user could flip through images and download the one he wants to use for a background to his photo library. The reason i need larger images is because of the iPad and how it needs images to be larger than the screen so it dosent rescale the image when switching between landscape and portrait.
uid: 17969 topic_id: 15661 reply_id: 58305


[TOPIC: post.html]
#9

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Regarding having display.save() save to the photo library, we've received that request before. Since you are able to specify the file name via that function, the tricky part is making sure it does not attempt to overwrite another file with the same name that it doesn't have write permission to. The display.captureScreen() function doesn't have this problem because it auto-names the file with a unique name.

That said, this feature is on our to-do list, but no plan on when we'll be implementing it yet.
uid: 32256 topic_id: 15661 reply_id: 58390


[TOPIC: post.html]
#10

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

How about we create a new function such as system.addFileToPhotoLibrary() which you would use like this...


local imageFileName = system.pathForFile("MyImage.jpg", system.DocumentsDirectory)
local photoLibraryFileName = system.addFileToPhotoLibrary(imageFileName)
[/code]

The idea is that it loads an image file from the app's directory to the device's photo library and it will automatically rename the file if necessary. The function will return the file's new name (if changed) and absolute path within the photo library.

The advantage of this method is that you can load files downloaded from the Internet, taken from the app's assets directory, taken from display.save(), or other sources.
uid: 32256 topic_id: 15661 reply_id: 58393


[TOPIC: post.html]
#11

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

That would be perfect for what I had in mind :)
uid: 17969 topic_id: 15661 reply_id: 58418


[TOPIC: post.html]
#12

chrislott

[GLOBAL: userInfoPane.html]
chrislott
  • Enthusiast

  • 39 posts
  • Corona SDK

Please please add this. Would be fantastic to have!
uid: 5022 topic_id: 15661 reply_id: 58421


[TOPIC: post.html]
#13

Peter Rich

[GLOBAL: userInfoPane.html]
Peter Rich
  • Enthusiast

  • 47 posts
  • Corona SDK

this would also be ideal for me. Let us know when it becomes available!
uid: 19999 topic_id: 15661 reply_id: 60144


[TOPIC: post.html]
#14

hdalaq

[GLOBAL: userInfoPane.html]
hdalaq
  • Observer

  • 1 posts
  • Corona SDK

Any news on the system.addFileToPhotoLibrary function ?! I hope to see such solution soon :D thanks
uid: 141423 topic_id: 15661 reply_id: 101121


[TOPIC: post.html]
#15

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

It's still on our wish list, but not scheduled yet. I'd like to see this implemented too, so please feel free to bug us about this periodically. Just as a constant friendly reminder. :)
uid: 32256 topic_id: 15661 reply_id: 101331


[TOPIC: post.html]
#16

vovasoft

[GLOBAL: userInfoPane.html]
vovasoft
  • Contributor

  • 131 posts
  • Corona SDK

Any news on the system.addFileToPhotoLibrary function ?
uid: 138389 topic_id: 15661 reply_id: 115160


[TOPIC: post.html]
#17

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Yes! We just added support for this in the past week. But unfortunately our daily build server has been giving us problems and has been failing to publish new builds. Our team is working on that, but in any case, keep a sharp eye out on our daily builds. The next one that becomes available will have what you need.
uid: 32256 topic_id: 15661 reply_id: 115190


[TOPIC: post.html]
#18

vovasoft

[GLOBAL: userInfoPane.html]
vovasoft
  • Contributor

  • 131 posts
  • Corona SDK

Ok. Thank you. It is very important feature.
Do you know if there will be also loadFileFromPhotoLibrary function avaible ?
uid: 138389 topic_id: 15661 reply_id: 115230


[TOPIC: post.html]
#19

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Everyone,

The newest daily build has the feature that you are looking for, although the build that it was in and its release notes are missing on our daily build page at the moment. Technical difficulties on our server that we have to sort out.

The new API for saving to the photo library looks like this...
media.save( filename [, baseDir] )


Here is an example on how to use it...
media.save( "MyPhoto.jpg", system.DocumentsDirectory )


If you do not provide a base directory, then the function will automatically use the
system.ResourceDirectory
.

On Android, you need to add the following permission to your build.settings file...
settings ={    androidPermissions =    {        "android.permission.WRITE_EXTERNAL_STORAGE",    },}

uid: 32256 topic_id: 15661 reply_id: 115414


[TOPIC: post.html]
#20

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

vovasoft,

We already have an API for fetching images from the photo library. It is
media.show()
. It will display the device's standard photo gallery picker to the user for selecting a photo. This API is documented here...
http://docs.coronalabs.com/api/library/media/show.html

On iOS, this is the only means of retrieving a photo from the photo library. iOS is sandboxed and does not allow you to access a photo file directly (ie: path\filename).
uid: 32256 topic_id: 15661 reply_id: 115416


[TOPIC: post.html]
#21

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

And what would be the path to use for the photo library?
uid: 17969 topic_id: 15661 reply_id: 115438


[TOPIC: post.html]
#22

vovasoft

[GLOBAL: userInfoPane.html]
vovasoft
  • Contributor

  • 131 posts
  • Corona SDK

I think you don't need to know the path to photo library. Corona will save it for you.
media.save( "MyPhoto.jpg", systemDocumentsDirectory )
uid: 138389 topic_id: 15661 reply_id: 115442


[TOPIC: post.html]
#23

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

You cannot set the destination path. That is out of your control. This is because the photo gallery on iOS is sandboxed, so this is out of our control too. You can only provide the source path of the image file that you want to add to the photo gallery.
uid: 32256 topic_id: 15661 reply_id: 115445


[TOPIC: post.html]
#24

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

Ah, I misread it, the basedir is of curse where the file is, not where its oing. Aweome, got pretty much all I need for now then fo my photo app :)
uid: 17969 topic_id: 15661 reply_id: 115452


[TOPIC: post.html]
#25

vovasoft

[GLOBAL: userInfoPane.html]
vovasoft
  • Contributor

  • 131 posts
  • Corona SDK

Joshua Quick, can you help me?
I'm trying to savethe full-resolution of an image from PhotoLibrary to system.DocumentsDirectory with
media.show( mediaSource, listener [, file] )

I added the "android.permission.CAMERA" and android.permission.WRITE_EXTERNAL_STORAGE" permissions
My version of this is:
local onComplete = function(event)   -- do nothingendfile ={	baseDir = system.DocumentsDirectory,	filename = "imageName.jpg",	type = "image"}media.show( media.PhotoLibrary, onComplete, file )

The image is saved but when I open it with default phone image viewer there is just black color.
uid: 138389 topic_id: 15661 reply_id: 115816



[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]