java.lang.Object | |
↳ | android.hardware.Camera |
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.
In order to use the device camera, you must declare the
CAMERA
permission in your Android
Manifest. Also be sure to include the
<uses-feature>
manifest element in order to declare camera features used by your application.
For example, if you use the camera and auto-focus feature, your Manifest
should include the following:
<uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" />
Caution: Different Android-powered devices may have different hardware specifications, such as megapixel ratings and auto-focus capabilities. In order for your application to be compatible with more devices, you should not make assumptions about the device camera specifications.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Camera.AutoFocusCallback | Handles the callback for the camera auto focus. | ||||||||||
Camera.ErrorCallback | Handles the camera error callback. | ||||||||||
Camera.Parameters | Handles the parameters for pictures created by a Camera service. | ||||||||||
Camera.PictureCallback | Handles the callback for when a picture is taken. | ||||||||||
Camera.PreviewCallback | Used to get a copy of each preview frame. | ||||||||||
Camera.ShutterCallback | An interface which contains a callback for the shutter closing after taking a picture. | ||||||||||
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Starts auto-focus function and registers a callback function to run when
camera is focused.
| |||||||||||
Cancels auto-focus function.
| |||||||||||
Returns the picture Parameters for this Camera service.
| |||||||||||
Lock the camera to prevent other processes from accessing it.
| |||||||||||
Returns a new Camera object.
| |||||||||||
Disconnects and releases the Camera object resources.
| |||||||||||
Registers a callback to be invoked when an error occurs.
| |||||||||||
Installs a callback to retrieve a single preview frame, after which the
callback is cleared.
| |||||||||||
Sets the Parameters for pictures from this Camera service.
| |||||||||||
Can be called at any time to instruct the camera to use a callback for
each preview frame in addition to displaying it.
| |||||||||||
Sets the SurfaceHolder to be used for a picture preview.
| |||||||||||
Start drawing preview frames to the surface.
| |||||||||||
Stop drawing preview frames to the surface.
| |||||||||||
Triggers an asynchronous image capture.
| |||||||||||
Triggers an asynchronous image capture.
| |||||||||||
Unlock the camera to allow another process to access it.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Is called before the object's memory is being reclaimed by the VM.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Media server died. In this case, the application must release the Camera object and instantiate a new one. @see #ErrorCallback
Unspecified camerar error. @see #ErrorCallback
Starts auto-focus function and registers a callback function to run when
camera is focused. Only valid after startPreview() has been called.
Applications should call getFocusMode()
to determine if this
method should be called. If the camera does not support auto-focus, it is
a no-op and onAutoFocus(boolean, Camera)
callback will be called immediately.
If your application should not be installed on devices without auto-focus, you must declare that your application uses auto-focus with the <uses-feature> manifest element.
If the current flash mode is not
FLASH_MODE_OFF
, flash may be
fired during auto-focus depending on the driver.
cb | the callback to run |
---|
Cancels auto-focus function. If the auto-focus is still in progress, this function will cancel it. Whether the auto-focus is in progress or not, this function will return the focus position to the default. If the camera does not support auto-focus, this is a no-op.
Returns the picture Parameters for this Camera service.
Lock the camera to prevent other processes from accessing it. To save setup/teardown time, a client of Camera can pass an initialized Camera object to another process. This method is used to re-lock the Camera object prevent other processes from accessing it. By default, the Camera object is locked. Locking it again from the same process will have no effect. Attempting to lock it from another process if it has not been unlocked will fail.
RuntimeException | if the method fails. |
---|
Disconnects and releases the Camera object resources.
It is recommended that you call this as soon as you're done with the Camera object.
Registers a callback to be invoked when an error occurs.
cb | the callback to run |
---|
Installs a callback to retrieve a single preview frame, after which the callback is cleared.
cb | A callback object that receives a copy of the preview frame. |
---|
Sets the Parameters for pictures from this Camera service.
params | the Parameters to use for this Camera service |
---|
Can be called at any time to instruct the camera to use a callback for each preview frame in addition to displaying it.
cb | A callback object that receives a copy of each preview frame. Pass null to stop receiving callbacks at any time. |
---|
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.
holder | the SurfaceHolder upon which to place the picture preview |
---|
IOException | if the method fails. |
---|
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 (NOTE: the data
may be null if the hardware does not have enough memory to make a copy).
The postview callback occurs when a scaled, fully processed postview
image is available (NOTE: not all hardware supports this). 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.
This method will stop the preview. Applications should not call stopPreview()
before this. After jpeg callback is received,
applications can call startPreview()
to restart the preview.
shutter | callback after the image is captured, may be null |
---|---|
raw | callback with raw image data, may be null |
postview | callback with postview image data, may be null |
jpeg | callback with jpeg image data, may be null |
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 (NOTE: the data
may be null if the hardware does not have enough memory to make a copy).
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.
This method will stop the preview. Applications should not call stopPreview()
before this. After jpeg callback is received,
applications can call startPreview()
to restart the preview.
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 |
Unlock the camera to allow another process to access it. To save setup/teardown time, a client of Camera can pass an initialized Camera object to another process. This method is used to unlock the Camera object before handing off the Camera object to the other process.
RuntimeException | if the method fails. |
---|
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.