I am bumping this up again because it is a critical problem. This worked before and now it is broken and no one is responding from Corona! Someone from Corona, please respond!!
bumping this issue again for lack of response. Please do not ignore me Corona!
I’m using capturePhoto, and it seems to work (having problems with display.save and displaycaptureBounds in graphics 2.0 though)…
I see you’re using build 1256? I just took another look at the doc page for capturePhoto and it says it is first available in 2013.1257 … (oops, that’s the doc revision I was looking at).
Anyways, can you post a code snippet and a short specific description of what vars come back nil / files aren’t written?
Thanks @mpappas. I’m using the version that supposedly fixed the event completed problem. Also, I’m testing this on an iPad Air with iOS 7.0.3. I’m using the example code (for testing purposes) that Rob Miracle posted in his tutorial. The only exemption is that I’m saving the photo file to the system.DocumentsDirectory. Here is the code below:
//\*FYI - picfile is the name of the file being saved to the system.DocumentsDirectory //The listener code shows the file on another scene //This exact code worked in a previous version of Corona local function goCameraroll() if media.hasSource( media.PhotoLibrary ) then media.selectPhoto( { mediaSource = media.PhotoLibrary, listener = completeCamera, --completePhoto, origin = cameraBtn.contentBounds, permittedArrowDirections = { "up", "down" }, destination = {baseDir=system.DocumentsDirectory, filename=picfile, type="image"} } ) else native.showAlert( "Warning", "This device does not have a camera.", { "OK" } ) end end
OK, so one thing is selectPhoto doesn’t scale (you mentioned scaling originally), it’s just supposed to save the photo out (or return a pointer to the photo loaded up as a display.object if you pass no destination) – In my case I’m using capturePhoto, and then using display.captureBounds to get a specific size image (not using selectPhoto at all), and then using display.save to save the final smaller (specific size) image out. (Which is currently gimped due to graphics 2.0 bugs it looks like). So since you posted the code for selectPhoto, our cases are more different (but capturePhoto works almost the same as selectPhoto according to the API’s).
Also, on first comparison of our code, yours looks fine… So, a couple more questions to try and help you debug through to the other side…
-It does show the cameraView and lets the user pick, and calls back the listener ok, right?
-
If you change the destination to system.TemporaryDirectory does it save out?
-
Can you post the listener with a little commentary about what is failing / status of event.completed and event.target? (true / nil?)
@mpappas - I’m sorry that I wasn’t clear. The selectPhoto & capturePhoto is not saving the image to the system.DocumentsDirectory (it did before). On my listener event I’m taking this image and displaying it, but since it is large, I want to scale or re-size it. I think the problem is that is it NOT saving the image to the system.DocumentsDirectory.
To answer your questions:
-
it shows the cameraView and either allows the user to pick a picture from the PhotoLibrary or take a picture
-
it does NOT save the picture to the system.DocumentsDirectory
-
the listener code simply takes the “saved image” and displays it according to the in the code but this is not working properly and the entire image is displaying (not the resized image as indicated in the code).
Hi,
I’ve just tried using media.selectPhoto to save an image to the system.DocumentsDirectory and it worked. Perhaps your picfile variable is nil?
Wait, the code you posted is supposed to save the image. The listener code (called completeCamera) will NOT receive a photo image in event.target (according to the api).
Can you show the listener completeCamera, and what is coming back in the event struct? for the code shown it looks like event.target should be nil, and event.completed should be true, right?
Here’s what happens from the listener event. I’ve included the display image function that shows the “saved photo file image” in the system.DocumentsDirectory:
//When the draw scene opens, it shows the "picfile" that was created from the selectPhoto/capturePhoto local function displayImage() if fileexists(picfile) then mypic = display.newImage( picfile, system.DocumentsDirectory ) if mypic.height \> mypic.width then --Portrait Picture mypic.xScale = .25 mypic.yScale = .25 mypic.x = myVariables.centerX mypic.y = myVariables.centerY group:insert(mypic) else //Landscape Picture mypic.xScale = .25 mypic.yScale = .25 mypic.x = myVariables.centerX mypic.y = myVariables.centerY group:insert(mypic) end mypic.x = myVariables.centerX mypic.y = myVariables.centerY group:insert(mypic) end end
So it sounds like it fails your if fileexists(picfile) test, yes?
Also, you said “but this is not working properly and the entire image is displaying (not the resized image as indicated in the code)”… Not sure how you could know this if there is no photo saved / no fileexists(). Other than that, it looks like you’re probably double inserting mypic into group (not that it would matter though, I think the sdk is fine with that).
Also note that dchan, a corona employee responded 3 posts above now that you’ve got some code showing
It’s a very weird thing. The image shows, but it is not resized according to the way I want it (see code above). I checked the files on my device and it is not saving the image to the system.DocumentsDirectory. All this was working prior to the latest Corona build.
ok, so something almost makes sense to me now (if the following is true)…
So the image shows onscreen after the camerview, but not scaled properly (0.25)…
Presuming the image is fullscreen, then it would seem that the capturePhoto call did not save the image, and instead just returned the image in event.target. (the question I was asking before about status of event var in the completion listener that you still haven’t answered…)
I am guessing that in the completion listener event.target has a non nil value… This is the normal case when selectPhoto returns an image instead of saving a file. You could likely change event.target.xScale = 0.25, and see the onscreen image change…
The question is why though… (never saw the real completion listener, completeCamera)…
Yes, you are absolutely right about that the image that shows onscreen is fullscreen and the capturePhoto call did not save the image, but just returned the image in event.target. Yes the completion listener event.target is a non nil value. I can try the xScale for the event.target, but the real issue is that the image is not being saved to the system.DocumentsDirectory and that is critical for our app. This worked in previous versions. Thanks @mpappas!
Well, don’t know what to do from here… It only happens on your iPad Air and works fine on iPad 3 you say? Ouch.
So it sounds like it isn’t able to save on the iPad Air one way or another… It sounds as if the code is behaving as if there was no “destination” parameter in the selectPhoto call. (I’m guessing there’s no soft error messages in the xcode console log either).
dchan was wondering about whether the filename was valid (picfile), perhaps something is different in the filename in this case? Like it’s trying to save a jpg as a png, or has a path or something else weird if you print it just before the selectPhoto call…
The file name is not the problem because that part of the code has been the same from day 1. What is the problem is that the selectPhoto routine is NOT saving the file in the system.DocumentsDirectory. This is the root of the problem on my end. Thanks @mpappas for hanging in there with me:)
Have you tried modifying the photopicker sample code to add the destination key in media.selectPhoto? So line 73 would look something like this:
timer.performWithDelay( 100, function() media.selectPhoto( { mediaSource = PHOTO\_FUNCTION, listener = sessionComplete, destination = {baseDir=system.DocumentsDirectory, filename="asdf.jpg", type="image"} } )
Thanks @mpapas for helping me today, you helped me pinpoint the problem. It seems to my code for the display image. Also, thanks @dchan for stepping in with some suggestions. I’ll do further testing later to make sure it is working properly.
Can you let us know what the problem was?
Thanks
Rob
@RobMiracle it turns out that the problem I was having had to do with the way I was displaying the photo image. I had some errors in my code and mpapas helped me find them. Thanks.