I don’t see any camera support under media. When are the API’s going to be updated? [import]uid: 28695 topic_id: 5943 reply_id: 305943[/import]
Funny, it’s not in the API section, but I found it in Docs.
http://developer.anscamobile.com/reference/video [import]uid: 6084 topic_id: 5943 reply_id: 20396[/import]
Media.Camera? that’s it? How do I open the shutter, take a picture, etc.?
I’m looking at Corona as a replacement for MonoTouch, but so far, I’m not impressed… documentation is severly lacking, hard to find things, etc. And there doesn’t appear to be any support other than from people like you…
So what do you get for your $350 annual subscription? [import]uid: 28695 topic_id: 5943 reply_id: 20400[/import]
The API, though could use a few updates, is where I figure out how to access many of the functions I need to get my game development going, but it’s the Docs page as well as the sample files (all under Resources) that I can sink my teeth into and get clumps of code that I can tear apart, analyze, and decipher for my own use.
If you’re new to Lua (and Corona in general) like me, you might want to pick up some of the books, as well as checking out the site in general:
Of course, post a question or your thoughts here as the site is full of helpful people. [import]uid: 6084 topic_id: 5943 reply_id: 20408[/import]
BeyoneTheTech: can you recommend a book or two on beginning game programming, specifically for the first timer using Lua.
I have an idea for a game, but haven’t a clue where to start.
Thanks… [import]uid: 28695 topic_id: 5943 reply_id: 20419[/import]
media.PlayVideo is in the API list at http://developer.anscamobile.com/reference/index/mediaplayvideo
Some more info can be found there as well. [import]uid: 8045 topic_id: 5943 reply_id: 20425[/import]
Luna: I don’t want to play video… I want to take pictures with the camera… [import]uid: 28695 topic_id: 5943 reply_id: 20428[/import]
Coincidental that this question was asked today, since I’m soon implementing this feature and have a couple questions as well:
[lua]local onComplete = function(event)
local photo = event.target
print( "photo w,h = " … photo.width … “,” … photo.height )
end
media.show( media.Camera, onComplete )[/lua]
The code example from the Docs page shows this, and while it works, it ends up “showing” the image on the screen afterwards.
How can I take a 1. picture with the camera without showing the result on the screen, followed by 2. resizing the image so it’s no larger than dimensions that I can specify? [import]uid: 6084 topic_id: 5943 reply_id: 20429[/import]
Sorry Rolf, I was replying to BeyondTech, I had hit the reply link under their response. This forum does not thread properly.
[import]uid: 8045 topic_id: 5943 reply_id: 20432[/import]
Luna: among other things!
[import]uid: 28695 topic_id: 5943 reply_id: 20435[/import]
The app I’m planning needs to capture an object, also without displaying it…
Is it me, or is there minimal camera support with Lua and I just don’t see it? [import]uid: 28695 topic_id: 5943 reply_id: 20436[/import]
I’m struggling with the camera object myself as I try to understand how it actually integrates with Corona.
This is where I found a camera sample app http://developer.anscamobile.com/content/camera
Here’s the sample lua code:
[lua]-- Camera not supported on Android devices in this build.
local isAndroid = “Android” == system.getInfo(“platformName”)
if(isAndroid) then
local alert = native.showAlert( “Information”, “Camera API not yet available on Android devices.”, { “OK”})
end
local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bkgd:setFillColor( 128, 0, 0 )
local text = display.newText( “Tap anywhere to launch Camera”, 0, 0, nil, 16 )
text:setTextColor( 255, 255, 255 )
text.x = 0.5 * display.contentWidth
text.y = 0.5 * display.contentHeight
local sessionComplete = function(event)
local t = event.target
print( "Camera ", ( t and “returned an image” ) or “session was cancelled” )
print( "event name: " … event.name )
print( "target: " … tostring( t ) )
if t then
local w = t.width
local h = t.height
print( “w,h = “… w …”,” … h )
end
end
local listener = function( event )
media.show( media.Camera, sessionComplete )
return true
end
bkgd:addEventListener( “tap”, listener )
[/lua] [import]uid: 8045 topic_id: 5943 reply_id: 20437[/import]
Thanks Luna… that helps immensely… maybe this isn’t going to be as hard as I thought…
How long have you been using Corona, if I may ask?
[import]uid: 28695 topic_id: 5943 reply_id: 20439[/import]
Rolf, I signed up last year around July during their $99 early adopter special. Corona has picked up a lot of steam since then. [import]uid: 8045 topic_id: 5943 reply_id: 20441[/import]
I was tinkering with the original sample code and got some weird results.
First, I made the photo variable as global and tried to do a photo:removeSelf() command afterwards.
What I got was a working result in the Simulator, but the bottom-right quarter of the captured image on the upper-left corner of my iPhone.
Come to think of it, maybe it’s because the Simulator doesn’t pull up the actual camera GUI, but opens a dialog box to select a JPEG file. In either case, when I do removeSelf, the selected image does disappear in Simulator mode. So, maybe I’m getting somewhere, but still lost.
[lua]local onComplete = function(event)
photo = event.target
print( "photo w,h = " … photo.width … “,” … photo.height )
end
…
…
media.show( media.Camera, onComplete )
photo:removeSelf()[/lua]
[import]uid: 6084 topic_id: 5943 reply_id: 20443[/import]
BeyondtheTech, that happened to me too. The x,y target origin has to be set to width/2 and height/2 to center the picture. For example:
[lua]-- code stuffs above…
t.x = 160
t.y = 240
– code stuffs below…[/lua]
If you don’t want to show the picture you just took, set the x,y origins to a number that moves it offscreen. It would still be there but you can’t see it. You can call another function to load a new screen.
[import]uid: 8045 topic_id: 5943 reply_id: 20444[/import]
Nope, Luna. I tried adjusting it all over the place, and it wasn’t moving.
But I think I’ve got it:
[lua]local onCameraComplete = function ( event )
local photo = event.target
if photo then
print ( "Captured photo, dimensions: " … photo.width … “x” … photo.height )
finalPhoto = photo
photo:removeSelf()
else
print ( “No photo taken” )
finalPhoto = nil
end
end
–
– regular logic here
media.show ( media.Camera, onCameraComplete )[/lua]
I’ve taken multiple pictures with it on my iPhone, and the image doesn’t stick around anymore. finalPhoto is the global variable that ends up holding the captured image. I guess it’s a workaround, but it will have to do. [import]uid: 6084 topic_id: 5943 reply_id: 20466[/import]
I did an image capture with media.Camera, saved it to a file with display.save and tried to re-display it, but the image quality is so poor.
It’s obviously grabbing something decent in photo.width/photo.height, but how do I get to display it again?
I tried replay=display.newImage(photo), but I’m getting a proxy error. [import]uid: 6084 topic_id: 5943 reply_id: 20538[/import]
BeyondtheTech,
That is exactly what was happening to me. I noticed the resolution was very low. I now wondering *if* there is a hi-res solution. Going over some of the docs now. [import]uid: 8045 topic_id: 5943 reply_id: 21146[/import]
I’ve thrown this issue over to Carlos in hopes he can make a quick adjustment in an upcoming daily build or something. I really want to see this work properly very soon! [import]uid: 6084 topic_id: 5943 reply_id: 21147[/import]