您的位置:首页 > 移动开发 > Android开发

android 调用系统相机

2016-01-20 11:07 211 查看
private void init(View view) {

btnCam1 = (ImageButton) view.findViewById(R.id.verify_img1);

btnCam2 = (ImageButton) view.findViewById(R.id.verify_img2);

//拍照

btnCam1.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

//intent.putExtra("btnCamId", "1");

intent.putExtra("camerasensortype", 2);//调用前置摄像头

intent.putExtra("autofocus", true);// 是否自动聚焦

intent.putExtra("fullScreen", true);// 是否全屏

intent.putExtra("showActionIcons", false);

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "DHCCFaceDetect.jpg")));

startActivityForResult(intent, 1);

}

});

//冲图库中获取图片

btnCam1.setOnLongClickListener(new OnLongClickListener() {

@Override

public boolean onLongClick(View v) {

Intent intent = new Intent(Intent.ACTION_PICK, null);

intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");

//intent.putExtra("btnCamId", "1");

startActivityForResult(intent, 2);

return true;

}

});

@Override

public void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {

case 1:

if (resultCode == Activity.RESULT_OK) {

File temp = new File(Environment.getExternalStorageDirectory() + "/DHCCFaceDetect.jpg");

startPhotoZoom(Uri.fromFile(temp), 4);

}

break;

case 2:

if (data != null) {

startPhotoZoom(data.getData(), 4);

}

break;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: