Take photos of Android phones (Android Learning Guide 9)

Source: Internet
Author: User

 

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.