1,通过intent调用camera
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");File photo = new File(Environment.getExternalStorageDirectory(),getPhotoFileName());Log.i(TAG,"getPhotoFileName():" +getPhotoFileName());intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));imageUri = Uri.fromFile(photo);startActivityForResult(intent, GET_PHOTO_WITH_CAMERA);private String getPhotoFileName() {Date date = new Date(System.currentTimeMillis());SimpleDateFormat dateFormat = new SimpleDateFormat("'IMG'_yyyy-MM-dd_HH-mm-ss");return dateFormat.format(date) + ".jpg";}


然后onActivityResult()中
if (requestCode == GET_PHOTO_WITH_CAMERA) {// doCropPhoto(mCurrentPhotoFile);Uri selectedImage = imageUri;Log.i(TAG, "uri:" + imageUri.toString());getContentResolver().notifyChange(selectedImage, null);ContentResolver cr = getContentResolver();Bitmap bitmap;try {bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage);BitmapDrawable bd = new BitmapDrawable(bitmap);headerImage.setBackgroundDrawable(bd);} catch (Exception e) {Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();}}

2,如果要调用gallery去剪辑的话
doCropPhoto(photo)
protected void doCropPhoto(File f) {try {// 启动gallery去剪辑这个照片final Intent intent = getCropImageIntent(Uri.fromFile(f));startActivityForResult(intent, GET_PHOTO_WITH_GALLARY);} catch (Exception e) {}}public static Intent getCropImageIntent(Uri photoUri) {Intent intent = new Intent("com.android.camera.action.CROP");intent.setDataAndType(photoUri, "image/*");intent.putExtra("crop", "true");intent.putExtra("aspectX", 1);intent.putExtra("aspectY", 1);intent.putExtra("outputX", 80);intent.putExtra("outputY", 80);intent.putExtra("return-data", true);return intent;}

更多相关文章

  1. android实践项目八做一个下载读条
  2. Android调用RESTful WCF服务
  3. android过滤第三应用列表
  4. Android启动和关闭Activity
  5. Android的EditText无法自动弹出输入法问题
  6. 2011.07.12——— android Foreground service
  7. Android(安卓)根据包名杀死应用后台进程
  8. Android实现开机自启动及开机自启动失败原因
  9. 新建android opengl工程

随机推荐

  1. android:visibility
  2. Android作为HTTP服务器--NanoHTTPD源码分
  3. Android 播放提示音
  4. android中调用相册里面的图片并返回
  5. 录音及播放音频文件
  6. jamendo_android 一个开源的Android在线
  7. android中的一个属性动画,可以显示更多的
  8. Android利用Looper在子线程中改变UI
  9. 编程回忆之Android回忆(Android应用参数的
  10. android 判断 网络 类型