Camera Class Overview

android sdk 描述
Class Overview
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. 

To access the device camera, you must declare the 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:

 <uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />To take pictures with this class, use the following steps:

1.Obtain an instance of Camera from open(int). 
2.Get existing (default) settings with getParameters(). 
3.If necessary, modify the returned Camera.Parameters object and call setParameters(Camera.Parameters). 
4.If desired, call setDisplayOrientation(int). 
5.Important: Pass a fully initialized SurfaceHolder to setPreviewDisplay(SurfaceHolder). Without a surface, the camera will be unable to start the preview. 
6.Important: Call startPreview() to start updating the preview surface. Preview must be started before you can take a picture. 
7.When you want, call takePicture(Camera.ShutterCallback, Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback) 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 startPreview() again first. 
9.Call stopPreview() to stop updating the preview surface. 
10.Important: Call release() to release the camera for use by other applications. Applications should release the camera immediately in onPause() (and re-open() it in onResume()). 
To quickly switch to video recording mode, use these steps:

1.Obtain and initialize a Camera and start preview as described above. 
2.Call unlock() to allow the media process to access the camera. 
3.Pass the camera to setCamera(Camera). See MediaRecorder information about video recording. 
4.When finished recording, call reconnect() to re-acquire and re-lock the camera. 
5.If desired, restart preview and take more photos or videos. 
6.Call stopPreview() and release() as described above. 
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 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.

你可能感兴趣的:(Camera Class Overview)