I’m having a problem taking and displaying a picture. The sample camera program works fine on my device, so I know it’s possible to use the camera and then display the image. My code works on the emulator, but not on my device.
Can anyone find where I’ve gone wrong in my code?
Why would my code work for the emulator but not the device?
module(…, package.seeall)
local widget = require(“widget”)
function new()
local localGroup = display.newGroup()
local bg = display.newRect(0, 0, display.contentWidth, display.contentHeight)
bg:setFillColor(240, 240, 240)
local commentLabel = display.newText(“Comments:”, 10, display.contentHeight - 120, Helvetica, 14)
commentLabel:setTextColor(0, 0, 0)
local commentBox = native.newTextField(10, display.contentHeight - 100, display.contentWidth - 20, 90)
local function sendInEmail(event)
local options =
{
to = {“john@doe.com”},
subject = “Test email”,
body = commentBox.text,
attachment = {filename = image, type = “image”},
}
native.showPopup(“mail”, options)
end
local function showPicture(event)
local image = event.target
if image then
image:scale(display.contentWidth/display.contentHeight, display.contentWidth/display.contentHeight)
image.x = display.contentWidth/2
image.y = display.contentHeight/2-50
local button_send = widget.newButton
{
left = display.contentWidth/2 - 60,
top = display.contentHeight - 160,
width = 120,
height = 40,
id = “button_2”,
label = “Send”,
fontSize = 14,
onEvent = sendInEmail,
}
end
end
local function takePicture(event)
if media.hasSource(media.Camera) then
media.show(media.Camera, showPicture)
else
native.showAlert(“Corona”, “Camera not found”)
end
end
local button_takepic = widget.newButton
{
left = display.contentWidth/2 - 75,
top = 30,
width = 150,
height = 40,
id = “button_1”,
label = “Take Picture”,
fontSize = 14,
onEvent = takePicture,
}
localGroup:insert(bg)
localGroup:insert(commentLabel)
localGroup:insert(commentBox)
localGroup:insert(button_takepic)
return localGroup
end

