The Camera class is used to set image capture settings, start/stop preview,
snap pictures, and retrieve frames for encoding for video.
See Also:
Camera Members
Syntax
[Android.Runtime.Register("android/hardware/Camera", DoNotGenerateAcw=true)]
[System.Obsolete("This class is obsoleted in this android platform")]
public class
Camera :
Java.Lang.ObjectRemarks
The Camera class is used to set image capture settings, start/stop preview,
snap pictures, and retrieve frames for encoding for video. This class is a
client for the Camera service, which manages the actual camera hardware.
xml Example
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
- Obtain an instance of Camera from Camera.Open(int).
- Get existing (default) settings with Camera.GetParameters.
- If necessary, modify the returned NoType:android/hardware/Camera$Parameters;Href=../../../reference/android/hardware/Camera.Parameters.html object and call
Camera.SetParameters(.Parameters).
- If desired, call Camera.SetDisplayOrientation(int).
- Important: Pass a fully initialized Android.Views.ISurfaceHolder to
Camera.SetPreviewDisplay(Android.Views.ISurfaceHolder). Without a surface, the camera
will be unable to start the preview.
- Important: Call Camera.StartPreview to start updating the
preview surface. Preview must be started before you can take a picture.
- When you want, call Camera.TakePicture(.IShutterCallback, .IPictureCallback, .IPictureCallback, .IPictureCallback) to
capture a photo. Wait for the callbacks to provide the actual image data.
- After taking a picture, preview display will have stopped. To take more
photos, call Camera.StartPreview again first.
- Call Camera.StopPreview to stop updating the preview surface.
- Important: Call Camera.Release to release the camera for
use by other applications. Applications should release the camera
immediately in Android.App.Activity.OnPause (and re-Camera.Open
it in Android.App.Activity.OnResume).
- Obtain and initialize a Camera and start preview as described above.
- Call Camera.Unlock to allow the media process to access the camera.
- Pass the camera to Android.Media.MediaRecorder.SetCamera(Camera).
See Android.Media.MediaRecorder information about video recording.
- When finished recording, call Camera.Reconnect to re-acquire
and re-lock the camera.
- If desired, restart preview and take more photos or videos.
- Call Camera.StopPreview and Camera.Release as described above.
Developer Guides
To access the device camera, you must declare the
NoType:android/Manifest$permission;Href=../../../reference/android/Manifest.permission.html#CAMERA permission in your Android
Manifest. Also be sure to include the
<uses-feature>
manifest element 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:
To take pictures with this class, use the following steps:
To quickly switch to video recording mode, use these steps:
This class is not thread-safe, and is meant for use from one event thread.
Most long-running operations (preview, focus, photo capture, etc) happen
asynchronously and invoke callbacks as necessary. Callbacks will be invoked
on the event thread Camera.Open(int) was called from. This class's methods
must never be called from multiple threads at once.
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.
For more information about using cameras, read the
Camera developer guide.
[Android Documentation]
Requirements
Namespace: Android.Hardware
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1