Android中照相机的使用

**功能:1.打开照相机
2.打开手机相册**
*
进行该功能需要onActivityResult方法接收回传值,代码如下:
“`

protected void onActivityResult(int requestCode,int      resultCode,Intent data){    super.onActivityResult(requestCode,resultCode,data);    }

// 从拍照的手机中获得照片

    if(requestCode==1000&&resultCode==RESULT_OK){        Bundle bundle=data.getExtras();        Bitmap bm=(Bitmap)bundle.get("data");        imageView.setImageBitmap(bm);    }else if(requestCode==1001&&resultCode==RESULT_OK){        Uri uri=data.getData();        ContentResolver resolver=getContentResolver();        try{            Bitmap bitmap= BitmapFactory.decodeStream(resolver.openInputStream(uri));            imageView.setImageBitmap(bitmap);        }catch(Exception e){            e.printStackTrace();        }    }}

// 使用意图打开本地照相机

       Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);            startActivityForResult(intent,1000);

// 从本地的图片库中获取图片

       Intent intent=new Intent(Intent.ACTION_GET_CONTENT);       intent.setType("image/*");//给意图设置类型(图片类型)       intent.putExtra("crop", true);       intent.putExtra("return-data", true);       startActivityForResult(intent,1001);`

更多相关文章

  1. android 调用相机拍照 并缩放切割图片
  2. 图片缩放设置
  3. android 实现图片上传功能 Tomcat作为服务器
  4. [Android]自定义图片左上角斜着的View
  5. android 加载图片轻松避免OOM(out of memory)

随机推荐

  1. Android(安卓)requires compiler complia
  2. android中读写sd卡文件
  3. Android: Support Libraries for Android
  4. android中使用wakelock
  5. android studio 加载.proto不能生成xxxDr
  6. Android小米5安装包解析失败问题
  7. android布局控件的用法
  8. Android(安卓)使用Handler的PostDelayed
  9. Activity的android:launchMode
  10. Android:简单的开场界面