Why does image stay on screen after Media.Save?

Hi,

Below in the code I capture an image and tell it to save it as picture1.jpg. After the Media.Save it shows the image on the screen of my phone and will not continue. Why is this? I am trying to do the login for Facebook after so I can upload the image in other code not shown here. Even with the facebook.Login not there the image still stays there. How do I get it to continue?

Thanks!


local onComplete = function(event)
local photo = event.target
media.save(“picture1.jpg”)
--print( "photo w,h = " … photo.width … “,” … photo.height )
facebook.login( appId, fbListener, { “publish_stream” } )
end

if media.hasSource( media.Camera ) then
media.show( media.Camera, onComplete )
else
native.showAlert( “Corona”, “This device does not have a camera.”, { “OK” } )
end

[import]uid: 184193 topic_id: 32655 reply_id: 332655[/import]

You need to just do -

photo.isVisible = false

after your -

photo = event.target

Dave [import]uid: 117617 topic_id: 32655 reply_id: 129842[/import]

Thanks, that took care of the photo but now I get a black screen after clicking save on the photo. I even added to show a message after it saves so I know it is about to start the login for Facebook which never shows. So who will it not show it? Below is my code:

MAIN:

local facebook = require "facebook"  
  
local appId = "1234567890"  
  
local onComplete = function(event)  
 local photo = event.target  
 photo.isVisible = false  
 media.save("picture1.jpg")  
 --print( "photo w,h = " .. photo.width .. "," .. photo.height )  
 native.showAlert( "Corona", "About to login to Facebook next.", { "OK" } )  
 facebook.login( appId, fbListener, { "publish\_stream" } )  
end  
  
if media.hasSource( media.Camera ) then  
 media.show( media.Camera, onComplete )  
else  
 native.showAlert( "Corona", "This device does not have a camera.", { "OK" } )  
end  
local function fbListener( event )  
 if event.isError then  
 native.showAlert( "ERROR", event.response, { "OK" } )  
 else  
 if event.type == "session" and event.phase == "login" then  
 -- login was a success; call function  
 onLoginSuccess()  
  
 elseif event.type == "request" then  
 -- this block is executed upon successful facebook.request() call  
  
 native.showAlert( "Success", "The photo has been uploaded.", { "OK" } )  
 end  
 end  
end  
  
local function onLoginSuccess()  
 -- Upload 'iheartcorona.jpg' to current user's account  
 local attachment = {  
 message = "Just a description of the photo.",  
 source = { baseDir=system.ResourceDirectory, filename="picture1.jpg", type="image" }  
 }  
  
 facebook.request( "me/photos", "POST", attachment )  
end  

BUILD:

-- Supported values for orientation:  
-- portrait, portraitUpsideDown, landscapeLeft, landscapeRight  
  
settings = {  
  
 orientation = {  
 default = "portrait",  
 supported = { "portrait", }  
 },  
  
 iphone = {  
 plist = {  
 UIStatusBarHidden = false,  
 UIPrerenderedIcon = true, -- set to false for "shine" overlay  
 --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend  
  
 --[[  
 -- iOS app URL schemes:  
 CFBundleURLTypes =  
 {  
 {  
 CFBundleURLSchemes =  
 {  
 "fbXXXXXXXXXXXXXX", -- example scheme for facebook  
 "coronasdkapp", -- example second scheme  
 }  
 }  
 }  
 --]]  
 }  
 },  
  
  
 androidPermissions = {  
 "android.permission.INTERNET",  
 "android.permission.CAMERA",  
 "android.permission.WRITE\_EXTERNAL\_STORAGE",  
 },  
  
}  

[import]uid: 184193 topic_id: 32655 reply_id: 129845[/import]

Change the order of your functions, usually a function is declared before it is called.

So have -

local function onLoginSuccess()
local function fbListener( event )
local onComplete = function(event)

Then your media stuff.

Dave [import]uid: 117617 topic_id: 32655 reply_id: 129867[/import]

You need to just do -

photo.isVisible = false

after your -

photo = event.target

Dave [import]uid: 117617 topic_id: 32655 reply_id: 129842[/import]

Thanks, that took care of the photo but now I get a black screen after clicking save on the photo. I even added to show a message after it saves so I know it is about to start the login for Facebook which never shows. So who will it not show it? Below is my code:

MAIN:

local facebook = require "facebook"  
  
local appId = "1234567890"  
  
local onComplete = function(event)  
 local photo = event.target  
 photo.isVisible = false  
 media.save("picture1.jpg")  
 --print( "photo w,h = " .. photo.width .. "," .. photo.height )  
 native.showAlert( "Corona", "About to login to Facebook next.", { "OK" } )  
 facebook.login( appId, fbListener, { "publish\_stream" } )  
end  
  
if media.hasSource( media.Camera ) then  
 media.show( media.Camera, onComplete )  
else  
 native.showAlert( "Corona", "This device does not have a camera.", { "OK" } )  
end  
local function fbListener( event )  
 if event.isError then  
 native.showAlert( "ERROR", event.response, { "OK" } )  
 else  
 if event.type == "session" and event.phase == "login" then  
 -- login was a success; call function  
 onLoginSuccess()  
  
 elseif event.type == "request" then  
 -- this block is executed upon successful facebook.request() call  
  
 native.showAlert( "Success", "The photo has been uploaded.", { "OK" } )  
 end  
 end  
end  
  
local function onLoginSuccess()  
 -- Upload 'iheartcorona.jpg' to current user's account  
 local attachment = {  
 message = "Just a description of the photo.",  
 source = { baseDir=system.ResourceDirectory, filename="picture1.jpg", type="image" }  
 }  
  
 facebook.request( "me/photos", "POST", attachment )  
end  

BUILD:

-- Supported values for orientation:  
-- portrait, portraitUpsideDown, landscapeLeft, landscapeRight  
  
settings = {  
  
 orientation = {  
 default = "portrait",  
 supported = { "portrait", }  
 },  
  
 iphone = {  
 plist = {  
 UIStatusBarHidden = false,  
 UIPrerenderedIcon = true, -- set to false for "shine" overlay  
 --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend  
  
 --[[  
 -- iOS app URL schemes:  
 CFBundleURLTypes =  
 {  
 {  
 CFBundleURLSchemes =  
 {  
 "fbXXXXXXXXXXXXXX", -- example scheme for facebook  
 "coronasdkapp", -- example second scheme  
 }  
 }  
 }  
 --]]  
 }  
 },  
  
  
 androidPermissions = {  
 "android.permission.INTERNET",  
 "android.permission.CAMERA",  
 "android.permission.WRITE\_EXTERNAL\_STORAGE",  
 },  
  
}  

[import]uid: 184193 topic_id: 32655 reply_id: 129845[/import]

Change the order of your functions, usually a function is declared before it is called.

So have -

local function onLoginSuccess()
local function fbListener( event )
local onComplete = function(event)

Then your media stuff.

Dave [import]uid: 117617 topic_id: 32655 reply_id: 129867[/import]

Thanks for the suggestion but that did not fix the issue. After I take the picture it goes to the black screen and stays there. I have a showAlert right after the media.save line so I would think the message would show since it is running the lines above it. If there is an error would it stop?

Thanks!

Warren
[import]uid: 184193 topic_id: 32655 reply_id: 129889[/import]

I don’t use media.save as the photo is used for other things, I use -

http://docs.coronalabs.com/api/library/display/capture.html

But that takes a screenshot (which is what I need).

Just reading about media.show though and it looks like you can tell it to save using the file parameter -

http://docs.coronalabs.com/api/library/media/show.html#file-optional

Dave [import]uid: 117617 topic_id: 32655 reply_id: 129891[/import]

How do I mark this thread resolved because the initial problem was resolved and I want to make a new thread for my new problem.

Thanks!
[import]uid: 184193 topic_id: 32655 reply_id: 129892[/import]

I don’t want to capture the screen. I want to save the image and then do something else after. It’s not doing anything after the media.save. Does anyone know why?
[import]uid: 184193 topic_id: 32655 reply_id: 129893[/import]

Thanks for the suggestion but that did not fix the issue. After I take the picture it goes to the black screen and stays there. I have a showAlert right after the media.save line so I would think the message would show since it is running the lines above it. If there is an error would it stop?

Thanks!

Warren
[import]uid: 184193 topic_id: 32655 reply_id: 129889[/import]

I don’t use media.save as the photo is used for other things, I use -

http://docs.coronalabs.com/api/library/display/capture.html

But that takes a screenshot (which is what I need).

Just reading about media.show though and it looks like you can tell it to save using the file parameter -

http://docs.coronalabs.com/api/library/media/show.html#file-optional

Dave [import]uid: 117617 topic_id: 32655 reply_id: 129891[/import]

How do I mark this thread resolved because the initial problem was resolved and I want to make a new thread for my new problem.

Thanks!
[import]uid: 184193 topic_id: 32655 reply_id: 129892[/import]

I don’t want to capture the screen. I want to save the image and then do something else after. It’s not doing anything after the media.save. Does anyone know why?
[import]uid: 184193 topic_id: 32655 reply_id: 129893[/import]

I tried to start a new thread on this different issue so I can get some help directly on it but Peach closed it due to duplicate topics. Now I can only hope people will read through all of this and see the NEW topic to help me since I can’t post again on it. Now I know better to ask another question in another thread since she will close any new ones. What a pain this is…

Does anyone know why the program stops after the media.save? I even commented it out and the app just stops after taking the picture. I WILL PAY someone to help me with this if needed. I need to take a picture, save the picture and then allow the app to keep running.

I’m not going to subscribe for the software if I can’t get this working at all. It seems basic but can’t even get it to work.

Can I post this as a job in the job forum without worrying it will get closed also?!!!

Help!
[import]uid: 184193 topic_id: 32655 reply_id: 129994[/import]

I tried to start a new thread on this different issue so I can get some help directly on it but Peach closed it due to duplicate topics. Now I can only hope people will read through all of this and see the NEW topic to help me since I can’t post again on it. Now I know better to ask another question in another thread since she will close any new ones. What a pain this is…

Does anyone know why the program stops after the media.save? I even commented it out and the app just stops after taking the picture. I WILL PAY someone to help me with this if needed. I need to take a picture, save the picture and then allow the app to keep running.

I’m not going to subscribe for the software if I can’t get this working at all. It seems basic but can’t even get it to work.

Can I post this as a job in the job forum without worrying it will get closed also?!!!

Help!
[import]uid: 184193 topic_id: 32655 reply_id: 129994[/import]

Keep your device connected when running your app and see if the Xcode console shows anything when it crashes.

Are you sure the file name is picture1.jpg ?

Dave [import]uid: 117617 topic_id: 32655 reply_id: 130082[/import]

Keep your device connected when running your app and see if the Xcode console shows anything when it crashes.

Are you sure the file name is picture1.jpg ?

Dave [import]uid: 117617 topic_id: 32655 reply_id: 130082[/import]