Use a camera to take a photo

Source: Internet
Author: User

Add the surfaceview Control for displaying the landscape view in the main. xml layout file:

<Surfaceview Android: layout_width = "fill_parent" Android: layout_height = "240dip" Android: Id = "@ + ID/surfaceview"/>

Surfaceview = (surfaceview) This. findviewbyid (R. Id. surfaceview );

Surfaceview. getholder (). setfixedsize (176,144); // sets the resolution.

/* Set the surface below not to maintain its own buffer, but to wait for the screen rendering engine to push the content to the user */

Surfaceview. getholder (). settype (surfaceholder. surface_type_push_buffers );

Camera camera = camera. open ();

Windowmanager WM = (windowmanager) getsystemservice (context. window_service );

Display display = WM. getdefaultdisplay ();

Camera. parameters = camera. getparameters ();

Parameters. setpreviewsize (display. getwidth (), display. getheight (); // you can specify the preview size.

Parameters. setpreviewframerate (3); // 3 frames per second

Parameters. setpictureformat (pixelformat. JPEG); // you can specify the photo output format.

Parameters. Set ("Jpeg-quality", 85); // photo quality

Parameters. setpicturesize (display. getwidth (), display. getheight (); // set the Photo size

Camera. setparameters (parameters );

Camera. setpreviewdisplay (surfaceview. getholder (); // you can use surfaceview to view the video.

Camera. startpreview (); // start previewing

Camera. autofocus (null); // auto focus

Camera. takepicture (null, callback); // take a photo

Camera. stoppreview (); // stop Preview

Camera. Release (); // release the camera

Androidmanifest. xml Main. xml

Takepicactivity

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.