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.
--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"]
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)
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?
--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
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
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.
---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
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.
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?
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...
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