[android] 06_我的照相机

Android 4.0

我的照相机

我的照相机
http://developer.android.com/guide/topics/media/camera.html
Building a Camera App
  • Detect and Access Camera - Create code to check for the existence of cameras and request access.
  • Create a Preview Class - Create a camera preview class that extends SurfaceView and implements theSurfaceHolder interface. This class previews the live images from the camera.
  • Build a Preview Layout - Once you have the camera preview class, create a view layout that incorporates the preview and the user interface controls you want.
  • Setup Listeners for Capture - Connect listeners for your interface controls to start image or video capture in response to user actions, such as pressing a button.
  • Capture and Save Files - Setup the code for capturing pictures or videos and saving the output.
  • Release the Camera - After using the camera, your application must properly release it for use by other applications.
步骤:
1、Detecting camera hardware 检测camera硬件,需要权限
Android 2.3 (API Level 9) 选择检测有几个摄像头: Camera.getNumberOfCameras()

2、Accessing cameras 使用camera
Android 2.3 (API Level 9) or higher , Camera.open(int)多个摄像头,打开指定的摄像头

3、Checking camera features 获取camera的配置信息
Camera.getParameters(),
Android 2.3 (API Level 9) or higher,When using API Level 9 or higher, use the Camera.getCameraInfo() to determine if a camera is on the front or back of the device, and the orientation of the image.

4、Creating a preview class 创建一个预览类

5、Placing preview in a layout  设置布局
android:screenOrientation="landscape" 水平朝向

6、Capturing pictures 照相片

7、Manifest Declarations 权限
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />