discard camera effects on Livecode

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

discard camera effects on Livecode

Post by cusingerBUSCw5N » Wed Nov 28, 2012 4:28 am

I am debugging my app - so I am trying all the different ways people can use it. If someone takes a picture and discards it, Livecode still says it's a picture and saves it (blank)...but in the process deletes another image called "client_background.png". There's nothing in my code that would delete this image - and I can't find anything special about the image settings that would connect it to the camera. But it consistently gets deleted - so when Livecode resumes, the app fails because it can't find that image.

I am wondering if there is code that can be used to stop the whole thing if the image is discarded - because it's rather stupid that my app says that it's saving a blank picture. If I can do that, maybe it would stop before it deleted my image.

Alternatively...why is my image being deleted?

I'm using an Android, Samsung Galaxy S3 running Ice Cream Sandwich 4.0.4 - if that matters.

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: discard camera effects on Livecode

Post by cusingerBUSCw5N » Wed Nov 28, 2012 4:30 am

Actually, this is more serious - because the image is permanently gone - so my app doesn't work any more.
This is not good.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: discard camera effects on Livecode

Post by sturgis » Wed Nov 28, 2012 5:28 am

Can you upload your stack so we can look at the code? Or post the code if you can't upload the stack.

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: discard camera effects on Livecode

Post by cusingerBUSCw5N » Wed Nov 28, 2012 4:55 pm

I stripped down my app to just the pictures page and for some reason mobilepickphoto "camera" isn't working on my test Android on my test app. However it is mimicking the problem - because instead of going to the camera, it grabs an image off the stack and uses it - and then, per my code, deletes it. (You can see it delete various images in the header).

The primary code is in button "take_picture".

The only difference between this and my real stack is that the real stack goes through the camera, and when you click discard, then takes and image off the stack and deletes it. I could get rid of the delete it code, but then when someone goes to another feature (uploading an existing image or taking a new picture), this image sometimes interferes with the process - so I thought the best thing was to delete it when it was done being saved.

Everything on my real app works fine - except when you discard a picture and don't take a new one....then it becomes a mess. I tried having it detect whether the image was empty or blank, but it didn't work.

So for my problem, either, mobilepickphoto "camera" needs to detect that there is no picture, or a workaround is that if it can't find the substitute image that it deleted, it can create a new one (by copying an image off the resources file).

If that is the workaround, I can figure out how to rename an existing image, but haven't figured out how to copy and existing backup image into a new image (since renaming a backup would only work one time.) Probably simple, but now I'm distracted trying to figure out why mobilepickphoto "camera" doesn't work on my example...

---------
Livecode can be great...and it can drive me nuts. I tried uploading my app - but apparently I don't have those privileges. So, here's the workaround:

First, I have posted the livecode app (stripped down for the picture card only) at http://www.toolsforbusiness.info/disast ... e.livecode
Here is the code for the button "take_picture"

Code: Select all

on mouseUp
   put mobileControlGet(mytwentyFirstInputField,text) into tname
   if tname is "blank" or tname is "" or tname is " " then
      answer "Please select a name before taking a picture."
   else
      put the width of this stack into tStackWidth
      put the height of this stack into tStackHeight
      --   ## Use 2% of the width or height for spacing
      put (tStackWidth * 0.02) into tHorizontalSpace
      put (tStackHeight * 0.02) into tVerticalSpace
      
      if the environment = "mobile" then
         //sets loc/size of image on stack
         set the lockloc of the templateimage to true
         set the width of the templateimage to tstackwidth*.40
         set the height of the templateimage to tstackwidth*.50
         set the left of the templateimage to the left of field "picture_field" + thorizontalspace*2
         set the top of the templateimage to tstackwidth*.40
         
              ##put field "tid" of card "docs" into tid
         put 19 into tid
         put tid & "_" & tname & ".png" into usethisname

         // select image from phone camera
         mobilepickphoto "camera"
                // names image "libimage"
         
         set the name of last image to "libImage"
         
         --   if the platform is "android" then
         --      answer "switching angle"
         --      set the angle  of image "libImage" to -90
         --      answer "done"
         --   end if
         set the top of image "libImage" to the bottom of field "label_save"
         set the left of image "libimage" to the left of button "cancel_existing"
         
         answer "Please wait for the picture to be saved."
         
         //uploads to ftp
         put "ftp://myftploginstuff/disaster/docs/" & usethisname into sendthis
         replace SPACE with "%20" in sendthis
       
         put image libImage into URL(sendthis)
       
             answer "Your picture was saved."
                 answer "We are now saving it to the remote database.  Click OK and wait for the Finished notice."
         
         put "http://mywebaddresswithextensions/add_resource_remote.cfm?id=" & tid & "&document_address=" & usethisname & "&docname=" & tname & "" into turl
         replace SPACE with "%20" in tURL
   
         put url (turl) into theData
               
         set the vis of button "take_picture" to false 

         set the vis of button "cancel_existing" to false
 
         set the vis of button "new_picture" to true
     
         set the vis of button "existing_image" to true
  
         set the vis of image "libImage" to false
      
         set the vis of field "label_save" to false
         if the environment is "mobile" and the platform is "android" then
         mobileControlSet "mytwentyFirstInputField", "visible", false 
      else
         set the vis of field "docname" to false
      end if
       put empty into image "libimage"
    
      delete the last image
         answer "Finished"
         
      end if     
   end if                                                                                                                                                                                                                                                                                                                  
end mouseUp

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: discard camera effects on Livecode

Post by Klaus » Wed Nov 28, 2012 5:08 pm

Hi cusingerBUSCw5N,

you need to check if the user CANCELed the "mobilepickphoto"!
Currrently you don't, then you rename image "client_background.png", which is "last image" in this case, to "libimage" and delete it (last image) in the end!

Code: Select all

...
mobilepickphoto "camera"
if the result = "cancel" then
  exit mouseup
end if
...
Best

Klaus

danieldz_2BUSalwT
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1
Joined: Thu Dec 13, 2012 9:31 pm

Re: discard camera effects on Livecode

Post by danieldz_2BUSalwT » Thu Feb 07, 2013 8:45 pm

Hello.

I'm new in LiveCode and I'm working on my first app.

I'm testing it and came into a problem with mobilePickPhoto too.

I have a button to take a picture and another one to choose an image from the album, then the image is displayed in the whole screen.

The problem is when I choose to take a picture with the camera, cancel it, and then choose to pick an image from the album. The image is inserted as a blank image.

If I try with another combination everything goes right:
- If I cancel the camera and choose to take a picture again the result is ok.
- If I cancel picking the image from the album and take a picture after it the result is ok.
- If I cancel picking the image from the album and choose to pick a picture again the result is ok.

The buttons to take the picture and to choose an image from the album are similar:

Code: Select all

on mouseUp
   mobilePickPhoto "camera"
   if the result is empty then
      put the cFoto of card "Foto" into tFotoc

      if tFotoc is not empty then
         delete image id tFotoc
         put empty into tFotoc
         set the cFoto of card "Foto" to tFotoc
      end if

      put the id of last image into tFotoid
      set the cFoto of card "Foto" to tFotoid

      set the width of image id tFotoid to the width of this card
      set the height of image id tFotoid to the height of this card
      set the layer of image id tFotoid to bottom
   end if
end mouseUp
I'll appreciate your help.

Daniel

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: discard camera effects on Livecode

Post by Klaus » Fri Feb 08, 2013 11:50 am

Hi Daniel,

1. welcome to the forum :D

2. please check my last posting (concerning the content of THE RESULT after the user cancelled) and compare it with your script 8)


Best

Klaus

Post Reply