Use the android. hardware. Camera class to take photos. The procedure is as follows:
A. Get the Camera instance object,
Camera camera = Camera. open ();
Alternatively, Camera camera = Camera. open (int cameraId );
CameraId indicates the camera device number, that is, the connection lock and preparation for use with the specified camera.
B. Obtain the specified camera parameters,
Camera. Parameters parameters = camera. getParameters ();
C. If necessary, encode the camera parameters as follows:
Parameters. setXXX ();
Camera. setParameters (prarameters );
D. If you want to camera at a certain angle, you can call the following function:
Camera. setDiaplayOrientation (int degrees );
The valid values of degrees are only 0 (landscape) and 90,180,270.
E. Call setPreviewDisp (SurfaceHolder) to preview the image by fully initializing SurfaceHolder.
F. Call startPreview () to update the surface, and the preview must start before you take a picture.
G. Call takePicture (Camera. ShutterCallback, Camera. PictureCallback) to capture the image. Besides, wait for callbacks to provide the actual image data.
H. After you get a picture, the preview will stop. If you want to take another picture, call startPreview ().
I. If you want to exit, stopPreview () and release () are called in sequence ().
Note: When using Camera, you must use the following permissions: android. permission. CAMERA. You can also set the camera features as needed, such:
<Uses-feature android: name = "android. hardware. camera"/> // The application uses the Camera device.
<Uses-feature android: name = "android. hardware. camera. autofocus"/> // you can set Camera to focus automatically.
From tianshijianbing1989