/** Android Development of the first camera image acquisition * Beijing Android Club Group: 167839253* Created on:2011-8-24* author:blueeagle* Email: [Email protected ]*/Here's a simple way to make a camera. To make a camera, you first need to add a photo permission. Add a method that is added in the Androidmanifest.xml file<uses-permission android:name= "Android.permission.CAMERA" >can be. Second: Modify the layout file: as shown in the following code. <textarea readonly name= "code"class= "html" ><?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com /apk/res/android "android:orientation= "Vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <Surfaceview Android:id= "@+id/mysurfaceview"Android:layout_width= "320px"Android:layout_height= "240px" > </SurfaceView> <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content" > <Button Android:id= "@+id/mybutton"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Open"/> <Button Android:id= "@+id/mybutton2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Off"/> </LinearLayout> </LinearLayout> </textarea>again, edit the code as follows:<textarea readonly name= "code"class= "Java" >/** Android Development camera Image Capture * Mytestcamera.java * Created on:2011-8-24 * author:blueeagle * Email: [Email protected ] */ PackageCom.blueeagle;Importjava.io.IOException;Importandroid.app.Activity;ImportAndroid.hardware.Camera;ImportAndroid.os.Bundle;ImportAndroid.view.SurfaceHolder;ImportAndroid.view.SurfaceView;ImportAndroid.view.View;ImportAndroid.widget.Button; Public classMytestcameraextendsActivityImplementssurfaceholder.callback{Camera Mycamera; Surfaceview Mysurfaceview; Surfaceholder Mysurfaceholder; Button MyButton1; Button MyButton2; BooleanIspreview =false; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); Mysurfaceview=(Surfaceview) Findviewbyid (R.id.mysurfaceview); MyButton1=(Button) Findviewbyid (R.id.mybutton); MyButton2=(Button) Findviewbyid (R.id.mybutton2); Mysurfaceholder=Mysurfaceview.getholder (); Mysurfaceholder.addcallback ( This); Mysurfaceholder.settype (surfaceholder.surface_type_push_buffers); Mybutton1.setonclicklistener (NewButton.onclicklistener () {@Override Public voidOnClick (View v) {Initcamera ();} }); Mybutton2.setonclicklistener (NewButton.onclicklistener () {@Override Public voidOnClick (View v) {if(mycamera!=NULL&&Amp;ispreview) {Mycamera.stoppreview (); Mycamera.release (); Mycamera=NULL; Ispreview=false; } } }); } Public voidInitcamera () {//TODO auto-generated Method Stubif(!Ispreview) {Mycamera=Camera.open ();} if(Mycamera! =NULL&&!Ispreview) { Try{mycamera.setpreviewdisplay (Mysurfaceholder); Mycamera.startpreview ();}Catch(IOException e) {e.printstacktrace ();} Ispreview=true; } } @Override Public voidSurfacechanged (Surfaceholder holder,intFormatintwidth,intheight) { //TODO auto-generated Method Stub} @Override Public voidsurfacecreated (Surfaceholder holder) {//TODO auto-generated Method Stub} @Override Public voidsurfacedestroyed (Surfaceholder holder) {//TODO auto-generated Method Stub} } </textarea><br>if running in the emulator, you can get the situation. If it is running on a real machine, it will turn on the camera, revealing the actual effect. When off, the screen will be closed. This basically can complete the image collection. If the camera is required in the program, it can be done in this way. This example is just a small demo. For in-depth study reference. <br>
Good article: If you like a yard-boy boy
Initial camera image acquisition of Android development