User Tools

Site Tools


built_in:cameraview

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
built_in:cameraview [2015/03/07 16:56]
octazid [Methods]
built_in:cameraview [2016/06/24 21:13] (current)
Line 1: Line 1:
 ====== CameraView control ====== ====== CameraView control ======
 +
 +//(Information and examples taken from the DroidScript documentation)//
 +
 ===== Description ===== ===== Description =====
-Create a camera preview control using the **CreateCameraView** function of the [[built_in:app|app]] object:+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.
Line 20: Line 23:
 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                                                                       ^ Description                                            
-|CameraView.AutoCapture( folder, fileName, maxCount ) | | +| CameraView.AutoCapture( folder, fileName, maxCount )                                                                                
-|CameraView.Destroy() | | +| CameraView.Destroy()                                                                                                                
-|CameraView.FindFaces( max )| | +| CameraView.FindFaces( max )                                                                                                         
-|CameraView.Focus() | | +| CameraView.Focus()                                                                                                                  
-|CameraView.GetAbsHeight() | | +| CameraView.GetAbsHeight()                                                                                                           
-|CameraView.GetAbsWidth() | | +| CameraView.GetAbsWidth()                                                                                                            
-|CameraView.GetCameraCount() | | +| CameraView.GetCameraCount()                                                                                                         
-|CameraView.GetColorEffects()| use in SetOnReady| +| CameraView.GetColorEffects()                                                 | use in SetOnReady                                      
-|CameraView.GetHeight() | | +| CameraView.GetHeight()                                                                                                              
-|CameraView.GetImageHeight() | | +| CameraView.GetImageHeight()                                                                                                         
-|CameraView.GetImageWidth() | | +| CameraView.GetImageWidth()                                                                                                          | 
-|CameraView.GetPictureSizes() | | +| CameraView.GetMaxZoom()                                                      |                                                        | 
-|CameraView.GetPixelData( format,left,top,width,height ) | | +| CameraView.GetParameters()                                                                                                          
-|CameraView.GetPosition() | | +| CameraView.GetPictureSizes()                                                                                                        
-|CameraView.GetType() | | +| CameraView.GetPixelData( format,left,top,width,height )                      format can be “rawbase64”, “pngbase64” or “jpgbase64”  
-|CameraView.GetVisibility() | | +| CameraView.GetPosition()                                                                                                            
-|CameraView.GetWidth() | | +| CameraView.GetType()                                                                                                                
-|CameraView.MotionMosaic( xtiles, ytiles, sensitivity, minPeriod, imageObj ) | | +| CameraView.GetVisibility()                                                                                                          
-|CameraView.Release() | | +| CameraView.GetWidth()                                                                                                               | 
-|CameraView.ReportColors( list,callback,sampSize,maxRate ) | | +| CameraView.GetZoom()                                                                                                                | 
-|CameraView.SetBackColor( color ) | | +| Cameraview.IsRecording()                                                                                                            
-|CameraView.SetBackGradient( color1,color2,color3,p4,p5,p6,p7 ) | | +| CameraView.MotionMosaic( xtiles, ytiles, sensitivity, minPeriod, imageObj )                                                         | 
-|CameraView.SetBackGradientRadial( x,y,r,color1,color2,color3,p7 ) | | +| CameraView.Record(file,seconds)                                                                                                     
-|CameraView.SetBackground( imagefile,options ) | | +| CameraView.Release()                                                                                                                
-|CameraView.SetColorEffect( effect )| use in SetOnReady| +| CameraView.ReportColors( list,callback,sampSize,maxRate )                                                                           
-|CameraView.SetFlash( onoff ) |set to true or false| +| CameraView.SetBackColor( color )                                                                                                    
-|CameraView.SetFocusMode( mode ) | | +| CameraView.SetBackGradient( color1,color2,color3,p4,p5,p6,p7 )                                                                      
-|CameraView.SetMargins( left,top,right,bottom ) | | +| CameraView.SetBackGradientRadial( x,y,r,color1,color2,color3,p7 )                                                                   
-|CameraView.SetOnMotion( callback ) | | +| CameraView.SetBackground( imagefile,options )                                                                                       
-|CameraView.SetOnPicture( callback ) | | +| CameraView.SetColorEffect( effect )                                          | use in SetOnReady                                      | 
-|CameraView.SetOnReady( callback ) | | +| CameraView.SetDuplicateImage( img1,img2 )                                    |                                                        
-|CameraView.SetPadding( left,top,right,bottom  ) | | +| CameraView.SetFlash( onoff )                                                 | set to true or false                                   
-|CameraView.SetPictureSize( width,height ) |Set size in pixel| +| CameraView.SetFocusMode( mode )                                                                                                     
-|CameraView.SetPosition( left, top, width, height ) | | +| CameraView.SetMargins( left,top,right,bottom )                                                                                      
-|CameraView.SetPreviewImage( imageObj ) | | +| CameraView.SetOnMotion( callback )                                                                                                  
-|CameraView.SetScale( x,y ) | | +| CameraView.SetOnPicture( callback )                                                                                                 
-|CameraView.SetSize( width, height ) | | +| CameraView.SetOnReady( callback )                                                                                                   
-|CameraView.SetSound( onoff ) | | +| CameraView.SetPadding( left,top,right,bottom                                                                                     | 
-|CameraView.SetVisibility( HideShow ) | | +| CameraView.SetParameter( name,value )                                        |                                                        
-|CameraView.StartPreview() | | +| CameraView.SetPictureSize( width,height )                                    | Set size in pixel                                      
-|CameraView.StopPreview() | | +| CameraView.SetPosition( left, top, width, height )                                                                                  
-|CameraView.Stream( ip,p2,quality,fps,p5 ) | | +| CameraView.SetPreviewImage( imageObj )                                                                                              
-|CameraView.TakePicture( fileName ) | |+| 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
  
 ---- ----
Line 75: Line 100:
  
   cam = app.CreateCameraView( 0.8, 0.4 );   cam = app.CreateCameraView( 0.8, 0.4 );
 +  
 +  cam.SetOnReady( cam_OnReady );
 +  
   lay.AddChild( cam );   lay.AddChild( cam );
-  setTimeout( "cam.StartPreview()", 1000 ); 
  
   app.AddLayout( lay );   app.AddLayout( lay );
 +}
 +
 +// Runs after "SetOnReady" as a callback
 +function cam_OnReady() {
 +  cam.StartPreview();
 } }
 </code> </code>
Line 106: Line 138:
   app.ShowPopup("Picture saved");   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> </code>
built_in/cameraview.1425747409.txt.gz · Last modified: 2015/03/08 00:56 (external edit)