1 //快速拍照法:---系统的
2 //实现拍照并显示在imageView中
3
4 public class MainActivity extends Activity implements OnClickListener {
5 ImageView imageView;
6
7 @Override
8 protected void onCreate(Bundle savedInstanceState) {
9 super.onCreate(savedInstanceState);
10 setContentView(R.layout.fragment_main);
11 Button button = (Button) findViewById(R.id.button1);
12 imageView = (ImageView) findViewById(R.id.imageView1);
13 button.setOnClickListener(this);
14 }
15
16 // 将图像保存到imageView
17 @Override
18 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
19 // TODO Auto-generated method stub
20 super.onActivityResult(requestCode, resultCode, data);
21 if (requestCode == 1) {
22 if (resultCode == Activity.RESULT_OK) {
23 Bitmap bitmap = (Bitmap) data.getExtras().get("data");
24 imageView.setImageBitmap(bitmap);
25 }
26 }
27 }
28
29 @Override
30 public void onClick(View v) {
31 // TODO Auto-generated method stub
32 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
33 startActivityForResult(intent, 1);
34
35 }
36
37 }
//-----------------------摄像-----------------------------
1 //快速摄像法:---系统的
2 //实现摄像并显示在videoView 中
3
4 public class MainActivity extends Activity implements OnClickListener {
5 VideoView videoView;
6
7 @Override
8 protected void onCreate(Bundle savedInstanceState) {
9 super.onCreate(savedInstanceState);
10 setContentView(R.layout.fragment_main);
11 Button button = (Button) findViewById(R.id.button1);
12 button.setOnClickListener(this);
13 videoView = (VideoView) findViewById(R.id.videoView1);
14 }
15
16 @Override
17 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
18 // TODO Auto-generated method stub
19 super.onActivityResult(requestCode, resultCode, data);
20 if (requestCode == 1) {
21 if (resultCode == Activity.RESULT_OK) {
22 Uri uri = data.getData();
23 Cursor cursor = this.getContentResolver().query(uri, null,
24 null, null, null);
25 if (cursor.moveToFirst()) {
26 String videoPath = cursor.getString(cursor
27 .getColumnIndex("_data"));
28 videoView.setVideoURI(Uri.parse(videoPath));
29 videoView.setMediaController(new MediaController(this));
30 videoView.start();
31
32 }
33
34 }
35 }
36 }
37
38 @Override
39 public void onClick(View v) {
40 // TODO Auto-generated method stub
41 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
42 startActivityForResult(intent, 1);
43 }
44
45 }