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}