Android中照相机的使用
16lz
2021-01-23
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);`
更多相关文章
- android 调用相机拍照 并缩放切割图片
- 图片缩放设置
- android 实现图片上传功能 Tomcat作为服务器
- [Android]自定义图片左上角斜着的View
- android 加载图片轻松避免OOM(out of memory)