简介
Android SDK支持Android设备内置的照相机。从Android2.3开始支持多个摄像头(主要指前置摄像头和后置摄像头)。通过照片相可以拍照和录像。
需要考虑的问题
是否支持照相机
快速拍照还是定制拍照
存储问题
照相机涉及的主要API
Intent听过action来启动系统的相机
Camera
SurfaceView
MediaRecorder(录像)
权限
“android.permission.CAMERA”
“android.permission.WRITE_EXTERNAL_STORAGE”
“android.permission.RECORD.AUDIO”
uses-feature:”android.hardware.camera”
拍照实例
public class MainActivity extends Activity { private ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); image = (ImageView) findViewById(R.id.image); findViewById(R.id.capture).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent,1); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { if (resultCode == Activity.RESULT_OK) { Bitmap cameraBitmap = (Bitmap) data.getExtras().get("data"); image.setImageBitmap(cameraBitmap); } } } }
效果图