Difference between revisions of "Camera.takePicture"
From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>") |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | + | '''Available since:''' Gideros 2021.8<br/> | |
− | ''' | + | '''Class:''' [[camera]]<br/> |
− | ''' | + | |
− | === | + | === Description === |
− | + | Takes a picture. | |
+ | <syntaxhighlight lang="lua"> | ||
+ | (boolean) = camera.takePicture() | ||
+ | </syntaxhighlight> | ||
+ | |||
This function must be called while preview is active, that is Camera.start() has been called. | This function must be called while preview is active, that is Camera.start() has been called. | ||
− | If it returns true, then the platform will asynchronously take a picture from the Camera (eventually using flash) then call Camera.onEvent callback one or more times. | + | |
− | It is your responsability to define Camera.onEvent before calling Camera.takePicture() | + | If it returns true, then the platform will asynchronously take a picture from the Camera (eventually using flash) then call Camera.onEvent callback one or more times. |
+ | |||
+ | '''It is your responsability to define Camera.onEvent before calling Camera.takePicture()''' | ||
+ | |||
Camera.onEvent function takes two arguments: | Camera.onEvent function takes two arguments: | ||
* a number, indicating the type of event | * a number, indicating the type of event | ||
Line 13: | Line 20: | ||
Event types are: | Event types are: | ||
− | * 0: shutter sound is triggered, data is empty (if supported) | + | * '''0''': shutter sound is triggered, data is empty (if supported) |
− | * 1: uncompressed image ready, data contains the uncompressed image (android only, optional) | + | * '''1''': uncompressed image ready, data contains the uncompressed image (android only, optional) |
− | * 2: jpeg image ready, data contains jpeg image. This event is always fired if takePicture() was successful | + | * '''2''': jpeg image ready, data contains jpeg image. This event is always fired if takePicture() was successful |
− | < | + | |
− | ( | + | === Return values === |
− | + | '''Returns''' (number) False if an error occured<br/> | |
+ | |||
+ | === Example === | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | require "camera" | ||
+ | local cw,ch=512,512 --Preview requested size | ||
+ | local pw,ph=8192,8192 -- Request a very large picture, os will give us what it can do at best | ||
+ | Camera.texture=RenderTarget.new(cw,ch,true) | ||
+ | cw,ch,pw,ph=Camera.start(Camera.texture,dev,pw,ph) | ||
+ | print("Using Camera Size:",cw,ch, "Picture:",pw,ph) | ||
− | = | + | Core.asyncCall(function() |
− | + | Core.yield(1) --Wait one second | |
− | + | Camera.setFlash(2) --Enable flash | |
+ | Camera.onEvent=function(evt,data) | ||
+ | print("Event:",evt,"Data:",#data) | ||
+ | end | ||
+ | print("takePic",Camera.takePicture()) | ||
+ | Camera.setFlash(0) --Set back flash to auto | ||
+ | end) | ||
+ | </syntaxhighlight> | ||
{{Camera}} | {{Camera}} |
Latest revision as of 14:27, 13 July 2023
Available since: Gideros 2021.8
Class: camera
Description
Takes a picture.
(boolean) = camera.takePicture()
This function must be called while preview is active, that is Camera.start() has been called.
If it returns true, then the platform will asynchronously take a picture from the Camera (eventually using flash) then call Camera.onEvent callback one or more times.
It is your responsability to define Camera.onEvent before calling Camera.takePicture()
Camera.onEvent function takes two arguments:
- a number, indicating the type of event
- a data buffer (string) depending on the event type
Event types are:
- 0: shutter sound is triggered, data is empty (if supported)
- 1: uncompressed image ready, data contains the uncompressed image (android only, optional)
- 2: jpeg image ready, data contains jpeg image. This event is always fired if takePicture() was successful
Return values
Returns (number) False if an error occured
Example
require "camera"
local cw,ch=512,512 --Preview requested size
local pw,ph=8192,8192 -- Request a very large picture, os will give us what it can do at best
Camera.texture=RenderTarget.new(cw,ch,true)
cw,ch,pw,ph=Camera.start(Camera.texture,dev,pw,ph)
print("Using Camera Size:",cw,ch, "Picture:",pw,ph)
Core.asyncCall(function()
Core.yield(1) --Wait one second
Camera.setFlash(2) --Enable flash
Camera.onEvent=function(evt,data)
print("Event:",evt,"Data:",#data)
end
print("takePic",Camera.takePicture())
Camera.setFlash(0) --Set back flash to auto
end)