In Android, camera preview is called.

Source: Internet
Author: User

 

The steps for calling camera preview in Android are as follows:

1. surfaceview Problems

 
//Define objectPrivateSurfaceview photoview;//Surfaceview object: (view component) Video DisplayPrivateSurfaceholder photoholder;//Surfaceholder object: (abstract interface) surfaceview support ClassPrivateCamera camera;//Camera object, camera Preview
//Surfaceview object settingsPhotoholder = photoview. getholder ();//Bind surfaceview to obtain the surfaceholder object.Photoholder. settype (surfaceholder. surface_type_push_buffers );//Set the display typePhotoholder. setfixedsize (100,100); Photoholder. addcallback (Callback);//Surfaceholder joins callback Interface

2. Implement the surfaceholder. Callback Interface

Surfaceholder. Callback Callback = New Surfaceholder. Callback () {@ override  Public   Void  Surfacedestroyed (surfaceholder holder ){  //  Todo auto-generated method stub              Camera. setpreviewcallback (null); camera. stoppreview (); camera. Release (); camera = NULL  ;} @ Override  Public   Void  Surfacecreated (surfaceholder holder ){ //  Todo auto-generated method stub             Camera = camera. open (); try {Camera. setpreviewdisplay (photoholder);} catch (ioexception e) {// todo auto-generated Catch Block  E. printstacktrace ();}} @ Override  Public   Void Surfacechanged (surfaceholder holder, Int Format, Int  Width,  Int Height ){  //  Todo auto-generated method stub  Initcamera ();}}; 

3. settings of the camera attribute

//Set camera attributesPublic VoidInitcamera() {Camera. parameters=Camera. getparameters ();// Obtain the camera attributesCamera. setdisplayorientation (90);// Rotate 90 degrees (if not set, it will be displayed horizontally)Camera. setparameters (parameters );// Save the property value to the Camera Parameter}

 

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.