调用系统拍照
// 如果点击的是拍照按钮
case R.id.btn_map_camera: {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_REQUESTCODE);
}
break;
// 调用系统的方法,进入拍照界面
/**
* 回调和拍照功能
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
case CAMERA_REQUESTCODE:
if (resultCode == Activity.RESULT_OK && data != null) {
Bitmap image = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
image.compress(CompressFormat.JPEG, 100, bos);
byte[] imagebytes = bos.toByteArray();// 照片信息
Bundle bundle = new Bundle();
bundle.putByteArray(CameraActivity.IMAGE_BUFFER, imagebytes);
Intent intent = new Intent();
intent.putExtras(bundle);
intent.setClass(MapActivity.this, CameraActivity.class);
startActivity(intent);
}
break;
default:
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}