User Tools

Site Tools


built_in:cameraview

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
built_in:cameraview [2014/09/17 19:13]
stevegarman created
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:+//(Information and examples taken from the DroidScript documentation)// 
 + 
 +===== Description ===== 
 +Create a camera preview control using the **CreateCameraView** function of the **[[built_in:app|app]]** object:
 <code>cam = app.CreateCameraView( width, height, options );</code> <code>cam = app.CreateCameraView( width, height, options );</code>
-This control allows your program to show a live feed of what is currently being seen by the phone/tablet's camera. If your device has a front facing camera and is at least version 2.3 of Android you can use the "Front" option to show the front camera's preview.+This control allows your program to show a live feed of what is currently being seen by the phone/tablet's camera. If your device has a front facing camera and is at least version 2.3 of Android you can use the **"Front"** option to show the front camera's preview.
  
-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).
 <code>cam.StartPreview();</code> <code>cam.StartPreview();</code>
 +
 +Use the **TakePicture** function to take a picture and save it to a given location.
 +<code>cam.TakePicture( filename );</code>
 +
 +Use the **SetPictureSize** function to set the dimensions in pixels of the pictures taken (eg. 1024 x 768).
 +<code>cam.SetPictureSize( width, height );</code>
 +
 +For more sophisticated examples including motion detection and video streaming, check out the **'Camera Stream'**, **'Camera Snap'** and **'Camera Motion'** sample programs in the DroidScript samples section.
 +
 +----
 ===== Methods ===== ===== Methods =====
-^Method ^Description ^ +Some controls use the same methods.\\ 
-|cam.AutoCapture| | +For examples of the **[[same methods]]** look here. 
-|cam.Focus| | +^ Method                                                                       ^ Description                                            
-|cam.GetCameraCount| | +CameraView.AutoCapture( folder, fileName, maxCount )                                                                                
-|cam.GetHeight| | +CameraView.Destroy()                                                                                                                | 
-|cam.GetImageHeight| | +| CameraView.FindFaces( max )                                                  |                                                        | 
-|cam.GetImageWidth| | +| CameraView.Focus()                                                                                                                  
-|cam.GetPictureSizes| | +CameraView.GetAbsHeight()                                                    |                                                        | 
-|cam.GetVisibility| | +| CameraView.GetAbsWidth()                                                                                                            | 
-|cam.GetWidth| | +| CameraView.GetCameraCount()                                                                                                         
-|cam.MotionMosaic| | +CameraView.GetColorEffects()                                                 | use in SetOnReady                                      | 
-|cam.Release| | +| CameraView.GetHeight()                                                                                                              
-|cam.SetBackColor| | +CameraView.GetImageHeight()                                                                                                         
-|cam.SetBackGradient| | +CameraView.GetImageWidth()                                                                                                          
-|cam.SetBackGradientRadial| | +CameraView.GetMaxZoom()                                                      |                                                        | 
-|cam.SetBackground| | +| CameraView.GetParameters()                                                                                                          | 
-|cam.SetFlash| | +| CameraView.GetPictureSizes()                                                                                                        
-|cam.SetFocusMode| | +CameraView.GetPixelData( format,left,top,width,height )                      | format can be “rawbase64”, “pngbase64” or “jpgbase64” 
-|cam.SetMargins| | +| CameraView.GetPosition()                                                                                                            | 
-|cam.SetOnMotion| | +| CameraView.GetType()                                                                                                                | 
-|cam.SetOnPicture| | +| CameraView.GetVisibility()                                                                                                          
-|cam.SetOnReady| | +CameraView.GetWidth()                                                                                                               
-|cam.SetPadding| | +CameraView.GetZoom()                                                                                                                | 
-|cam.SetPictureSize| | +| Cameraview.IsRecording()                                                                                                            | 
-|cam.SetPosition| | +| CameraView.MotionMosaic( xtiles, ytiles, sensitivity, minPeriod, imageObj )                                                         
-|cam.SetPreviewImage| | +CameraView.Record(file,seconds)                                              |                                                        | 
-|cam.SetSize| | +| CameraView.Release()                                                                                                                
-|cam.SetSound| | +CameraView.ReportColors( list,callback,sampSize,maxRate )                    |                                                        | 
-|cam.SetVisibility| | +| CameraView.SetBackColor( color )                                                                                                    
-|cam.StartPreview| | +CameraView.SetBackGradient( color1,color2,color3,p4,p5,p6,p7 )                                                                      
-|cam.StopPreview| | +CameraView.SetBackGradientRadial( x,y,r,color1,color2,color3,p7 )                                                                   
-|cam.Stream| | +CameraView.SetBackground( imagefile,options )                                                                                       
-|cam.TakePicture| |+CameraView.SetColorEffect( effect )                                          | use in SetOnReady                                      | 
 +| CameraView.SetDuplicateImage( img1,img2 )                                    |                                                        | 
 +| CameraView.SetFlash( onoff )                                                 set to true or false                                   
 +CameraView.SetFocusMode( mode )                                                                                                     
 +CameraView.SetMargins( left,top,right,bottom )                                                                                      
 +CameraView.SetOnMotion( callback )                                                                                                  
 +CameraView.SetOnPicture( callback )                                                                                                 
 +CameraView.SetOnReady( callback )                                                                                                   
 +CameraView.SetPadding( left,top,right,bottom  )                                                                                     
 +CameraView.SetParameter( name,value )                                        |                                                        | 
 +| CameraView.SetPictureSize( width,height )                                    Set size in pixel                                      
 +CameraView.SetPosition( left, top, width, height )                                                                                  
 +CameraView.SetPreviewImage( imageObj )                                                                                              
 +CameraView.SetScale( x,y )                                                                                                          | 
 +| CameraView.SetSize( width, height )                                                                                                 
 +CameraView.SetSound( onoff )                                                                                                        
 +CameraView.SetVisibility( HideShow )                                                                                                
 +CameraView.SetZoom( level )                                                  |                                                        | 
 +| CameraView.StartPreview()                                                                                                           
 +CameraView.Stop()                                                            |                                                        | 
 +| CameraView.StopPreview()                                                                                                            
 +CameraView.Stream( ip,p2,quality,fps,p5 )                                                                                           
 +CameraView.TakePicture( fileName )                                                                                                  | 
 + 
 +---- 
 + 
 +===== Options ===== 
 + 
 +These are the camera resolution options:   
 + 
 +  * CIF 
 +  * QVGA 
 +  * SVGA 
 +  * VGA 
 +  * XGA 
 +  * UXGA 
 + 
 +---- 
 + 
 +====Example - Show camera preview==== 
 + 
 +<code javascript> 
 +function OnStart() 
 +
 +  lay = app.CreateLayout( "Linear", "VCenter,FillXY" ); 
 + 
 +  cam = app.CreateCameraView( 0.8, 0.4 ); 
 +   
 +  cam.SetOnReady( cam_OnReady ); 
 +   
 +  lay.AddChild( cam ); 
 + 
 +  app.AddLayout( lay ); 
 +
 + 
 +// Runs after "SetOnReady" as a callback 
 +function cam_OnReady() { 
 +  cam.StartPreview(); 
 +
 +</code> 
 + 
 +====Example - Take pictures==== 
 + 
 +<code javascript> 
 +function OnStart() 
 +
 +  lay = app.CreateLayout( "Linear", "VCenter,FillXY" ); 
 + 
 +  cam = app.CreateCameraView( 0.8, 0.4 ); 
 +  lay.AddChild( cam ); 
 +  cam.SetPictureSize( 1024, 768 ); 
 +  setTimeout( "cam.StartPreview()", 1000 ); 
 + 
 +  btn = app.CreateButton( "Snap", 0.3, -1 ); 
 +  btn.SetOnTouch( Snap ); 
 +  lay.AddChild( btn ); 
 + 
 +  app.AddLayout( lay ); 
 +
 + 
 +function Snap() 
 +
 +  cam.TakePicture( "/sdcard/MyPic.jpg" ); 
 +  app.ShowPopup("Picture saved"); 
 +
 +</code> 
 + 
 +====Example - Record Video==== 
 + 
 +<code javascript> 
 + 
 +//Called when application is started.  
 +function OnStart()  
 +{     
 + //Fix orientation to landscape since  
 + //most phones cameras work this way.     
 + app.SetOrientation( "Landscape" );  
 +     
 + //Create horizontal layout that fills the screen.  
 + lay = app.CreateLayout( "Linear", "Horizontal,FillXY,VCenter" );  
 + lay.SetBackground( "/res/drawable/pattern_carbon", "repeat" );  
 +   
 + //Create camera view control.  
 + cam = app.CreateCameraView( 0.6, 0.8 );  
 + cam.SetOnReady( cam_OnReady );  
 + cam.SetMargins( 0, 0, 0.04, 0 );  
 + lay.AddChild( cam );    
 +  
 + //Create vertical layout on right for other stuff.  
 + layRight = app.CreateLayout( "Linear", "Vertical" );  
 + lay.AddChild( layRight );  
 +  
 + //Create record button.  
 + btn = app.CreateButton( "Record", 0.2, 0.15, "Alum" );  
 + btn.SetMargins( 0, 0.06, 0, 0 );  
 + btn.SetOnTouch( btn_OnTouch );  
 + layRight.AddChild( btn );   
 +  
 + //Add main layout to app.  
 + app.AddLayout( lay );  
 +  
 + //Create a folder for recordings.  
 + recFolder = "/sdcard/Videos";  
 + app.MakeFolder( recFolder );  
 +}  
 + 
 +//Called when camera is ready.  
 +function cam_OnReady()  
 +{  
 +    //Set focus mode and start preview.  
 +    cam.SetFocusMode( "Video" );  
 +    cam.StartPreview();  
 +}  
 + 
 +//Handle record button.  
 +function btn_OnTouch()  
 +{  
 + if( cam.IsRecording() )   
 + {  
 +     //Stop recording and update button.  
 +     cam.Stop();  
 +     btn.SetText( "Record" );  
 + }  
 + else   
 + {  
 +     //Start recording and update button.  
 +     cam.Record( recFolder+"/test.mp4" );  
 +     btn.SetText( "Stop" );  
 + }  
 +}  
 + 
 +</code>
built_in/cameraview.txt · Last modified: 2016/06/24 21:13 (external edit)