Android调用系统相机简单实现
来源:互联网 发布:空间数据的拓扑关系 编辑:程序博客网 时间:2024/04/29 23:09
- Android调用系统相机简单实现
- 项目简单介绍
- 关键代码
- 项目源码
Android调用系统相机简单实现
项目简单介绍
调用系统相机两种简单的实现方法,两种都是想调用系统相机进行拍到,第一种返回data中的数据,是缩略图,第二种照片是先保存再通过uri取出,保存的是原图。
关键代码
activity_main.xml中的代码如下:
<!-- 两种实现方式 设置两个按钮 --> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/Mode1" android:onClick="mode1" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/Mode2" android:onClick="mode2" /> <!-- 设置一个View用于显示图片 --> <ImageView android:id="@+id/iv" android:layout_width="match_parent" android:layout_height="match_parent"/>
上面的代码很简单,没必要再做解释,下面是MainActivity.java中的代码:
/* * 方式一点击事件实现 * */ public void mode1(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, Mode_1); } /* * 方式二点击事件实现 * */ public void mode2(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri photoUri = Uri.fromFile(new File(mFilePath)); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); startActivityForResult(intent, Mode_2); } /* * 重新返回函数的代码 * */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK){ if(requestCode == Mode_1){ Bundle bundle = data.getExtras(); Bitmap bitmap = (Bitmap) bundle.get("data"); mImageView.setImageBitmap(bitmap); } else if(requestCode == Mode_2){ FileInputStream fis = null; try { fis = new FileInputStream(mFilePath); Bitmap bitmap = BitmapFactory.decodeStream(fis); mImageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { e.printStackTrace(); }finally{ try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
项目源码
点击下载源码
1 0
- Android调用系统相机简单实现
- Android调用系统相机拍照,并且模仿实现水印相机简单功能
- Android调用系统相机拍照,并且模仿实现水印相机简单功能
- Android调用系统相机拍照,并且模仿实现水印相机简单功能
- android调用系统相机实现拍照功能
- android调用系统相机实现拍照功能
- android调用系统相机实现拍照功能
- android调用系统相机实现拍照功能
- android调用系统相机实现拍照功能
- android调用系统相机实现拍照功能
- Android 调用系统相机
- 调用系统相机 Android
- android调用系统相机
- android 调用系统相机
- android 调用系统相机
- android调用系统相机
- android 调用系统相机
- Android 调用系统相机
- 【C语言】递归实现栈的逆序及排序
- markdown写博客工具
- 求职应聘时面试常见问题1
- Struts2基础复习系列(3)
- 怎样去阅读技术书籍
- Android调用系统相机简单实现
- android框架搭建——二次封装Volley框架
- nginx+ngrok的配置
- 数据结构--向量--二分查找
- pat 1024. Palindromic Number (25)
- 什么时候需要使用display:block;属性?
- 【PA2014】【BZOJ3712】Fiolki
- 80x86浮点数和整数的内部结构
- 为您的创业公司推荐5款类Slack开源协作工具