Call the system front camera in the Android system

Source: Internet
Author: User

Starting from Android 2.3 Gingerbread, native supports front cameras. Next we will look at how to call the front camera in the program.

The first method is to use mediastore to call the system's native camera.

Intent intent = new intent (mediastore. action_image_capture); </P> <p> intent. putextra ("camerasensortype", 2); // call the front camera <br/> intent. putextra ("autofocus", true); // auto focus <br/> intent. putextra ("fullscreen", false); // full screen <br/> intent. putextra ("showactionicons", false); </P> <p> startactivityforresult (intent, pick_from_camera );

Another method is to use the camera framework. In earlier versions, only camera is used in the SDK. the open () method calls the rear camera. Now this method accepts a parameter to determine whether it is a front camera or a rear camera. We also use the new camerainfo class and getcamerainfo method to obtain the detailed camera information on the Android device, and getnumberofcameras () to obtain the number of cameras. The typical Call method is as follows:

Int cameracount = 0; <br/> camera cam = NULL; </P> <p> camera. camerainfo = new camera. camerainfo (); <br/> cameracount = camera. getnumberofcameras (); // get cameras number </P> <p> for (INT camidx = 0; camidx <cameracount; camidx ++) {<br/> camera. getcamerainfo (camidx, camerainfo); // get camerainfo <br/> If (camerainfo. facing = camera. camerainfo. camera_facing_front) {// specifies the orientation of the camera. Currently, the two defined values are camera_facing_front front and camera_facing_back. <br/> try {<br/> cam = camera. open (camidx); <br/>} catch (runtime1_tione) {<br/> E. printstacktrace (); <br/>}< br/>}

 

The advantage of using the camera framework is that it provides a large number of APIS, such as setdisplayorientation and camera. parameters is used to implement powerful functions, and urfaceholder is also used. after interfaces such as Callback, shuttercallback, and picturecallback, you can customize interfaces and functions to freely implement the required interface layout and image processing effects. For example:


Related Article

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.