Building an iOS app that takes pictures, first time always crashes
Geoff Canyon
gcanyon at gmail.com
Tue Dec 10 00:55:35 EST 2013
I'm testing on iOS 7.0.4 on a 4S, and every time I build a new version, it
crashes when trying to take a photo, until I take one with the
front-faceing camera. That succeeds, and from then on either camera will
work most of the time, but every once in a while, the back camera will die.
Any ideas? The code I'm using is below:
on takePhoto
if the environment is "mobile" then
mobilePickPhoto "camera",300,300
if the result is "cancel" then
exit takePhoto
end if
else
answer file "pick an image:"
import paint from file it
end if
put the long id of the last control of this cd into imageID
set the lockLoc of imageID to true
toSquare 300,imageID
set the loc of imageID to the loc of this cd
set relayerGroupedControls to true
set the layer of imageID to the layer of imageID
set the alphadata of imageID to the uAlphaData of this stack
enable control "start" of group "controls"
set the blendlevel of control "start" of group "controls" to 0
end takePhoto
on toSquare S,imageID
put the width of imageID into W
put the height of imageID into H
if W = H and W <> S then
set the width of imageID to S
set the height of imageID to S
crop image id (the short id of imageID) to the rect of imageID
else if W < H then
put round(S * H / W) into H
put the rect of imageID into imageRect
put item 1 of imageRect + S into item 3 of imageRect
put item 2 of imageRect + H into item 4 of imageRect
set the rect of imageID to imageRect
put (item 4 of imageRect + item 2 of imageRect - S) div 2 into item 2
of imageRect
put item 2 of imageRect + S into item 4 of imageRect
crop image id (the short id of imageID) to imageRect
else
put round(S * W / H) into W
put the rect of imageID into imageRect
put item 1 of imageRect + W into item 3 of imageRect
put item 2 of imageRect + S into item 4 of imageRect
set the rect of imageID to imageRect
put (item 3 of imageRect + item 1 of imageRect - S) div 2 into item 1
of imageRect
put item 1 of imageRect + S into item 3 of imageRect
crop image id (the short id of imageID) to imageRect
end if
set the loc of imageID to the loc of this cd
end toSquare
More information about the use-livecode
mailing list