public class

Camera

extends Object
java.lang.Object
   ↳ android.hardware.Camera

Class Overview

The Camera class is used to connect/disconnect with the camera service, set capture settings, start/stop preview, snap a picture, and retrieve frames for encoding for video.

There is no default constructor for this class. Use open() to get a Camera object.

Summary

Nested Classes
public class Camera.AutoFocusCallback Handles the callback for the camera auto focus. 
public class Camera.ErrorCallback Handles the camera error callback. 
public class Camera.Parameters Handles the parameters for pictures created by a Camera service. 
public class Camera.PictureCallback Handles the callback for when a picture is taken. 
public class Camera.PreviewCallback Used to get a copy of each preview frame. 
public class Camera.ShutterCallback An interface which contains a callback for the shutter closing after taking a picture. 
public class Camera.Size Handles the picture size (dimensions). 
Constants
int CAMERA_ERROR_SERVER_DIED Media server died.
int CAMERA_ERROR_UNKNOWN Unspecified camerar error.
Public Methods
final void autoFocus(Camera.AutoFocusCallback cb)
Starts auto-focus function and registers a callback function to run when camera is focused.
Camera.Parameters getParameters()
Returns the picture Parameters for this Camera service.
static Camera open()
Returns a new Camera object.
final void release()
Disconnects and releases the Camera object resources.
final void setErrorCallback(Camera.ErrorCallback cb)
Registers a callback to be invoked when an error occurs.
final void setOneShotPreviewCallback(Camera.PreviewCallback cb)
Installs a callback to retrieve a single preview frame, after which the callback is cleared.
void setParameters(Camera.Parameters params)
Sets the Parameters for pictures from this Camera service.
final void setPreviewCallback(Camera.PreviewCallback cb)
Can be called at any time to instruct the camera to use a callback for each preview frame in addition to displaying it.
final void setPreviewDisplay(SurfaceHolder holder)
Sets the SurfaceHolder to be used for a picture preview.
final void startPreview()
Start drawing preview frames to the surface.
final void stopPreview()
Stop drawing preview frames to the surface.
final void takePicture(Camera.ShutterCallback shutter, Camera.PictureCallback raw, Camera.PictureCallback jpeg)
Triggers an asynchronous image capture.
Protected Methods
void finalize()
Is called before the object's memory is being reclaimed by the VM.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int CAMERA_ERROR_SERVER_DIED

Media server died. In this case, the application must release the Camera object and instantiate a new one. @see #ErrorCallback

Constant Value: 100 (0x00000064)

public static final int CAMERA_ERROR_UNKNOWN

Unspecified camerar error. @see #ErrorCallback

Constant Value: 1 (0x00000001)

Public Methods

public final void autoFocus (Camera.AutoFocusCallback cb)

Starts auto-focus function and registers a callback function to run when camera is focused. Only valid after startPreview() has been called.

Parameters
cb the callback to run

public Camera.Parameters getParameters ()

Returns the picture Parameters for this Camera service.

public static Camera open ()

Returns a new Camera object.

public final void release ()

Disconnects and releases the Camera object resources.

It is recommended that you call this as soon as you're done with the Camera object.

public final void setErrorCallback (Camera.ErrorCallback cb)

Registers a callback to be invoked when an error occurs.

Parameters
cb the callback to run

public final void setOneShotPreviewCallback (Camera.PreviewCallback cb)

Installs a callback to retrieve a single preview frame, after which the callback is cleared.

Parameters
cb A callback object that receives a copy of the preview frame.

public void setParameters (Camera.Parameters params)

Sets the Parameters for pictures from this Camera service.

Parameters
params the Parameters to use for this Camera service

public final void setPreviewCallback (Camera.PreviewCallback cb)

Can be called at any time to instruct the camera to use a callback for each preview frame in addition to displaying it.

Parameters
cb A callback object that receives a copy of each preview frame. Pass null to stop receiving callbacks at any time.

public final void setPreviewDisplay (SurfaceHolder holder)

Sets the SurfaceHolder to be used for a picture preview. If the surface changed since the last call, the screen will blank. Nothing happens if the same surface is re-set.

Parameters
holder the SurfaceHolder upon which to place the picture preview
Throws
IOException if the method fails.

public final void startPreview ()

Start drawing preview frames to the surface.

public final void stopPreview ()

Stop drawing preview frames to the surface.

public final void takePicture (Camera.ShutterCallback shutter, Camera.PictureCallback raw, Camera.PictureCallback jpeg)

Triggers an asynchronous image capture. The camera service will initiate a series of callbacks to the application as the image capture progresses. The shutter callback occurs after the image is captured. This can be used to trigger a sound to let the user know that image has been captured. The raw callback occurs when the raw image data is available. The jpeg callback occurs when the compressed image is available. If the application does not need a particular callback, a null can be passed instead of a callback method.

Parameters
shutter callback after the image is captured, may be null
raw callback with raw image data, may be null
jpeg callback with jpeg image data, may be null

Protected Methods

protected void finalize ()

Is called before the object's memory is being reclaimed by the VM. This can only happen once the VM has detected, during a run of the garbage collector, that the object is no longer reachable by any thread of the running application.

The method can be used to free system resources or perform other cleanup before the object is garbage collected. The default implementation of the method is empty, which is also expected by the VM, but subclasses can override finalize() as required. Uncaught exceptions which are thrown during the execution of this method cause it to terminate immediately but are otherwise ignored.

Note that the VM does guarantee that finalize() is called at most once for any object, but it doesn't guarantee when (if at all) finalize() will be called. For example, object B's finalize() can delay the execution of object A's finalize() method and therefore it can delay the reclamation of A's memory. To be safe, use a ReferenceQueue, because it provides more control over the way the VM deals with references during garbage collection.