Android.Hardware.Camera Class
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.Object

Remarks

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" />
  1. Obtain an instance of Camera from Camera.Open(int).
  2. Get existing (default) settings with Camera.GetParameters.
  3. If necessary, modify the returned NoType:android/hardware/Camera$Parameters;Href=../../../reference/android/hardware/Camera.Parameters.html object and call Camera.SetParameters(.Parameters).
  4. If desired, call Camera.SetDisplayOrientation(int).
  5. 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.
  6. Important: Call Camera.StartPreview to start updating the preview surface. Preview must be started before you can take a picture.
  7. When you want, call Camera.TakePicture(.IShutterCallback, .IPictureCallback, .IPictureCallback, .IPictureCallback) to capture a photo. Wait for the callbacks to provide the actual image data.
  8. After taking a picture, preview display will have stopped. To take more photos, call Camera.StartPreview again first.
  9. Call Camera.StopPreview to stop updating the preview surface.
  10. 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).
  1. Obtain and initialize a Camera and start preview as described above.
  2. Call Camera.Unlock to allow the media process to access the camera.
  3. Pass the camera to Android.Media.MediaRecorder.SetCamera(Camera). See Android.Media.MediaRecorder information about video recording.
  4. When finished recording, call Camera.Reconnect to re-acquire and re-lock the camera.
  5. If desired, restart preview and take more photos or videos.
  6. 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