Page 1 of 2
Saving a photo as a file to be retrieved later
Posted: Mon Apr 15, 2013 7:22 am
by jekyllandhyde
Well, after lots of trial and error I failed to figure out how to save a photo the user has just taken with the camera as a file. After it saves on my card I want to be able to display it again if the user quits the App and then returns later to the same screen/card. Every time the user takes a photo it will replace the previous photo.
Here is a portion of my button script, the question is what do I add at the end to save the jpg image as a file in the documents subdirectory of the iPhone and then what script do I need to retrieve it? Also where should the "retrieve file" script be place if not in preOpenCard? This is probably so simple, I'm a bit embarrassed to ask.
Code: Select all
--now we get a photo (button script)
set the lockloc of the templateimage to true
set the width of the templateimage to "240"
set the height of the templateimage to "320"
set the left of the templateimage to "205"
set the top of the templateimage to "292"
mobilepickphoto "rear camera", 960, 1280
put the last image into tAttachment["data"]
put "hazard.jpg" into tAttachment["name"]
Re: Saving a photo as a file to be retrieved later
Posted: Mon Apr 15, 2013 8:54 am
by jmburnod
Hi jekyllandhyde
To save an img to file in document folder:
Code: Select all
on ExportImgToFile pName
put specialfolderPath("documents") & "/" & pName & "png" into tPathIMG
put the short id of last img into tIdImg
export image id tIdImg to tPathIMG as png
end ExportImgToFile
To retrieve it:
You have to write the tPathIMG in a file (preferences user).
On preopenstack you have to read this file and store its content somewhere (custom prop, global var)
Best regards
Jean-Marc
Re: Saving a photo as a file to be retrieved later
Posted: Tue Apr 16, 2013 6:07 am
by jekyllandhyde
I created an empty image box named "picture" on the page in exactly the same place where "the template image" is. I used your example to save the file then on preOpenCard I load it into the empty image box but nothing happens? Still confused. Perhaps my syntax is wrong?
Code: Select all
--in my photo taking button script
put specialfolderPath("documents") & "/hazardpicture" into tPathIMG
put the short id of last img into tldImg
export image id tIdImg to tPathIMG as jpeg
---end of button script
on PreOpenCard
-------this trys to display the last photo
put specialfolderpath("documents") & "/hazardpicture" into tPathgetIMG
if there is not a file tPathgetIMG then
put empty into URL ("file:" & tPathgetIMG)
else
put URL ("file:" & tPathgetIMG) into thelastImage
put thelastImage into image "picture"
end if
end PreOpenCard
Re: Saving a photo as a file to be retrieved later
Posted: Tue Apr 16, 2013 8:43 am
by jmburnod
Hi kekylllandhide,
Use binfile to import data of the img OR "set the filename" to set the reference file of the img
Code: Select all
on PreOpenCard
-------this trys to display the last photo
put specialfolderpath("documents") & "/hazardpicture" into tPathgetIMG
if there is a file tPathgetIMG then
-- put empty into URL ("file:" & tPathgetIMG) -- You make the file empty
put URL ("binfile:" & tPathgetIMG) into last img -- import data into the image
--set the filename of last img to tPathgetIMG -- ref image file only
else
put "" into last img -- imagedata = empty
--set the filename of last img to empty -- ref image file = empty
end if
end PreOpenCard
Best regards
Jean-Marc
Re: Saving a photo as a file to be retrieved later
Posted: Tue Apr 16, 2013 6:34 pm
by jekyllandhyde
Jean-Marc,
Thanks for your all your help. It seems that the script skips getting the file because it answers "there is no file". Very puzzling because I use a similar routine to save text into text files and it works great. I have used mobilepickphoto library because I am testing in the simulator. Here is my code.
Code: Select all
---button script to get a photo
set the lockloc of the templateimage to true
set the width of the templateimage to "240"
set the height of the templateimage to "320"
set the left of the templateimage to "205"
set the top of the templateimage to "292"
-- comment out the next line before finalizing code and swap with next line
mobilepickphoto "library"
-- mobilepickphoto "rear camera", 960, 1280
put specialfolderPath("documents") & "/hazardpic" into tPathIMG
put the short id of last img into tldImg
export image id tldImg to tPathIMG as jpeg
----end button script
on PreOpenCard
put specialfolderpath("documents") & "/hazardpic" into tPathgetIMG
if there is a file tPathgetIMG then
put URL ("binfile:" & tPathgetIMG) into last img
answer "there is a file"
else
put "" into last img
answer "there is no file"
end if
put last img into image "picture"
end PreOpenCard
Re: Saving a photo as a file to be retrieved later
Posted: Tue Apr 16, 2013 6:49 pm
by jmburnod
I think simulator is the problem, Try the same on the device. It should work
Re: Saving a photo as a file to be retrieved later
Posted: Tue Apr 16, 2013 8:35 pm
by jekyllandhyde
Just tested it but no luck.
Re: Saving a photo as a file to be retrieved later
Posted: Tue Apr 16, 2013 10:42 pm
by jmburnod
I saw we forgot the .jpg suffix
Code: Select all
put specialfolderPath("documents") & "/hazardpic" & ".jpg" into tPathIMG
Re: Saving a photo as a file to be retrieved later
Posted: Wed Apr 17, 2013 4:45 am
by jekyllandhyde
I have a bunch of text files saved with no extension so I doubt it needs one. Having said that, on your advice, I changed the code and added the extension on the save and retrieve code. No difference, it still doesn't work.
Re: Saving a photo as a file to be retrieved later
Posted: Wed Apr 17, 2013 5:03 am
by Simon
Not to be critical but saving an image file is not difficult.
Could you post a stack?
Simon
Re: Saving a photo as a file to be retrieved later
Posted: Wed Apr 17, 2013 5:27 am
by Dixie
J&K...
instead of :
Code: Select all
put thelastImage into image "picture"
try:
Code: Select all
set the filename of image "picture" to tPathgetIMG
Dixie
Re: Saving a photo as a file to be retrieved later
Posted: Wed Apr 17, 2013 9:06 pm
by jekyllandhyde
I'm confused, if the code is answering "there is no image", how is "set the filename of image "picture" to tPathgetIMG" going to do anything? Clearly the code can't find a file? I'm a beginner so please correct me if I'm wrong?
Re: Saving a photo as a file to be retrieved later
Posted: Wed Apr 17, 2013 10:12 pm
by jmburnod
Hi jekyllandhyde,
I'm confused, if the code is answering "there is no image", how is "set the filename of image "picture" to tPathgetIMG" going to do anything?
Yes you're right
Re: Saving a photo as a file to be retrieved later
Posted: Wed Apr 17, 2013 10:19 pm
by Dixie
J&K...
I thought that you were past the problem of being able to save an image from the camera !... well, anyway... I have attached a stack that will let you take a photo... it will always display the last photo that was taken... and display the last photo that was taken when you relaunch the stack...
There are two handlers to look at... one in the 'camera' button and the other in the script of the stack...
Dixie
Re: Saving a photo as a file to be retrieved later
Posted: Wed Apr 17, 2013 10:28 pm
by jmburnod
Hi Dixie,
I thought that you were past the problem of being able to save an image from the camera !
Yes. I already use a part of your script for long time and it work fine but I want understand what happen with the jekyllandhyde 's stack
Be well
Jean-Marc