This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
built_in:cameraview [2015/01/07 09:44] octazid [Methods] |
built_in:cameraview [2016/06/24 13:13] leandroap [Example - Show camera preview] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== CameraView control ====== | ====== CameraView control ====== | ||
- | ===== Create | + | |
- | Create a camera preview control using the CreateCameraView function of the app object: | + | // |
+ | |||
+ | ===== Description | ||
+ | Create a camera preview control using the **CreateCameraView** function of the **[[built_in: | ||
< | < | ||
- | This control allows your program to show a live feed of what is currently being seen by the phone/ | + | This control allows your program to show a live feed of what is currently being seen by the phone/ |
- | You will need to call the StartPreview function of the CameraView control to start the preview (Note: On some phones it is neccessary to wait at least one second before calling the StartPreview function). | + | You will need to call the **StartPreview** function of the CameraView control to start the preview\\ (Note: On some phones it is neccessary to wait at least one second before calling the StartPreview function). |
< | < | ||
+ | |||
+ | Use the **TakePicture** function to take a picture and save it to a given location. | ||
+ | < | ||
+ | |||
+ | Use the **SetPictureSize** function to set the dimensions in pixels of the pictures taken (eg. 1024 x 768). | ||
+ | < | ||
+ | |||
+ | For more sophisticated examples including motion detection and video streaming, check out the **' | ||
+ | |||
+ | ---- | ||
===== Methods ===== | ===== Methods ===== | ||
Some controls use the same methods.\\ | Some controls use the same methods.\\ | ||
For examples of the **[[same methods]]** look here. | For examples of the **[[same methods]]** look here. | ||
- | ^Method ^Description ^ | + | ^ Method |
- | |CameraView.AutoCapture( | + | | CameraView.AutoCapture( |
- | |CameraView.Destroy() | | | + | | CameraView.Destroy() |
- | |CameraView.Focus() | | | + | | CameraView.FindFaces( max ) | |
- | |CameraView.GetAbsHeight() | | | + | | CameraView.Focus() |
- | |CameraView.GetAbsWidth() | | | + | | CameraView.GetAbsHeight() |
- | |CameraView.GetCameraCount() | | | + | | CameraView.GetAbsWidth() |
- | |CameraView.GetHeight() | | | + | | CameraView.GetCameraCount() |
- | |CameraView.GetImageHeight() | | | + | | CameraView.GetColorEffects() |
- | |CameraView.GetImageWidth() | | | + | | CameraView.GetHeight() |
- | |CameraView.GetPictureSizes() | | | + | | CameraView.GetImageHeight() |
- | |CameraView.GetPixelData( format, | + | | CameraView.GetImageWidth() |
- | |CameraView.GetPosition() | | | + | | CameraView.GetMaxZoom() |
- | |CameraView.GetType() | | | + | | CameraView.GetParameters() |
- | |CameraView.GetVisibility() | | | + | | CameraView.GetPictureSizes() |
- | |CameraView.GetWidth() | | | + | | CameraView.GetPixelData( format, |
- | |CameraView.MotionMosaic( | + | | CameraView.GetPosition() |
- | |CameraView.Release() | | | + | | CameraView.GetType() |
- | |CameraView.ReportColors( list, | + | | CameraView.GetVisibility() |
- | |CameraView.SetBackColor( | + | | CameraView.GetWidth() |
- | |CameraView.SetBackGradient( | + | | CameraView.GetZoom() |
- | |CameraView.SetBackGradientRadial( | + | | Cameraview.IsRecording() |
- | |CameraView.SetBackground( | + | | CameraView.MotionMosaic( |
- | |CameraView.SetFlash( onoff ) |set to true or false| | + | | CameraView.Record(file, |
- | |CameraView.SetFocusMode( mode ) | | | + | | CameraView.Release() |
- | |CameraView.SetMargins( left, | + | | CameraView.ReportColors( list, |
- | |CameraView.SetOnMotion( callback ) | | | + | | CameraView.SetBackColor( |
- | |CameraView.SetOnPicture( callback ) | | | + | | CameraView.SetBackGradient( |
- | |CameraView.SetOnReady( callback ) | | | + | | CameraView.SetBackGradientRadial( |
- | |CameraView.SetPadding( | + | | CameraView.SetBackground( |
- | |CameraView.SetPictureSize( width, | + | | CameraView.SetColorEffect( effect ) | use in SetOnReady |
- | |CameraView.SetPosition( | + | | CameraView.SetDuplicateImage( img1, |
- | |CameraView.SetPreviewImage( | + | | CameraView.SetFlash( onoff ) |
- | |CameraView.SetScale( x,y ) | | | + | | CameraView.SetFocusMode( mode ) | | |
- | |CameraView.SetSize( | + | | CameraView.SetMargins( left, |
- | |CameraView.SetSound( onoff ) | | | + | | CameraView.SetOnMotion( callback ) |
- | |CameraView.SetVisibility( | + | | CameraView.SetOnPicture( callback ) | | |
- | |CameraView.StartPreview() | | | + | | CameraView.SetOnReady( callback ) | | |
- | |CameraView.StopPreview() | | | + | | CameraView.SetPadding( |
- | |CameraView.Stream( | + | | CameraView.SetParameter( name, |
- | |CameraView.TakePicture( | + | | CameraView.SetPictureSize( width, |
+ | | CameraView.SetPosition( | ||
+ | | CameraView.SetPreviewImage( | ||
+ | | CameraView.SetScale( x,y ) | ||
+ | | CameraView.SetSize( | ||
+ | | CameraView.SetSound( onoff ) | ||
+ | | CameraView.SetVisibility( | ||
+ | | CameraView.SetZoom( level ) | | ||
+ | | CameraView.StartPreview() | ||
+ | | CameraView.Stop() | ||
+ | | CameraView.StopPreview() | ||
+ | | CameraView.Stream( | ||
+ | | CameraView.TakePicture( | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Options ===== | ||
+ | |||
+ | These are the camera resolution options: | ||
+ | |||
+ | * CIF | ||
+ | * QVGA | ||
+ | * SVGA | ||
+ | * VGA | ||
+ | * XGA | ||
+ | * UXGA | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====Example - Show camera preview==== | ||
+ | |||
+ | <code javascript> | ||
+ | function OnStart() | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | cam = app.CreateCameraView( 0.8, 0.4 ); | ||
+ | |||
+ | cam.SetOnReady( cam_OnReady ); | ||
+ | |||
+ | lay.AddChild( cam ); | ||
+ | |||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | |||
+ | // Runs after " | ||
+ | function cam_OnReady() { | ||
+ | cam.StartPreview(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ====Example - Take pictures==== | ||
+ | |||
+ | <code javascript> | ||
+ | function OnStart() | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | cam = app.CreateCameraView( 0.8, 0.4 ); | ||
+ | lay.AddChild( cam ); | ||
+ | cam.SetPictureSize( 1024, 768 ); | ||
+ | setTimeout( " | ||
+ | |||
+ | btn = app.CreateButton( " | ||
+ | btn.SetOnTouch( Snap ); | ||
+ | lay.AddChild( btn ); | ||
+ | |||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | |||
+ | function Snap() | ||
+ | { | ||
+ | cam.TakePicture( "/ | ||
+ | app.ShowPopup(" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ====Example - Record Video==== | ||
+ | |||
+ | <code javascript> | ||
+ | |||
+ | // | ||
+ | function OnStart() | ||
+ | { | ||
+ | // | ||
+ | // | ||
+ | app.SetOrientation( " | ||
+ | |||
+ | // | ||
+ | lay = app.CreateLayout( " | ||
+ | lay.SetBackground( "/ | ||
+ | |||
+ | // | ||
+ | cam = app.CreateCameraView( 0.6, | ||
+ | cam.SetOnReady( cam_OnReady ); | ||
+ | cam.SetMargins( 0, | ||
+ | lay.AddChild( cam ); | ||
+ | |||
+ | // | ||
+ | layRight = app.CreateLayout( " | ||
+ | lay.AddChild( layRight ); | ||
+ | |||
+ | // | ||
+ | btn = app.CreateButton( " | ||
+ | btn.SetMargins( 0, | ||
+ | btn.SetOnTouch( btn_OnTouch ); | ||
+ | layRight.AddChild( btn ); | ||
+ | |||
+ | // | ||
+ | app.AddLayout( lay ); | ||
+ | |||
+ | // | ||
+ | recFolder = "/ | ||
+ | app.MakeFolder( recFolder ); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | function cam_OnReady() | ||
+ | { | ||
+ | // | ||
+ | cam.SetFocusMode( " | ||
+ | cam.StartPreview(); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | function btn_OnTouch() | ||
+ | { | ||
+ | if( cam.IsRecording() ) | ||
+ | { | ||
+ | // | ||
+ | cam.Stop(); | ||
+ | btn.SetText( " | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | // | ||
+ | cam.Record( recFolder+"/ | ||
+ | btn.SetText( " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ |