Android(安卓)调用系统摄像头
16lz
2022-05-23
在开发android 应用的时候我们经常需要用到摄像头来进行拍照或者是录制视频,这里介绍一种最简单的方法:调用系统摄像头来拍照,并将照片保存起来
启动摄像头的方法:
拍摄成功后接收参数的接收方法我们只需要重写
启动摄像头的方法:
startActivityForResult(new Intent("android.media.action.IMAGE_CAPTURE"), TAKE_PICTURE);
拍摄成功后接收参数的接收方法我们只需要重写
protected void onActivityResult(int requestCode, int resultCode, Intent data)方法即可 如: final int TAKE_PICTURE = 1;protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == TAKE_PICTURE) { if (resultCode == RESULT_OK) { Bitmap bm = (Bitmap) data.getExtras().get("data"); imgPhoto.setImageBitmap(bm); sdCardExit = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); if (sdCardExit) { myRecAudioDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/custom_picture"); if (!myRecAudioDir.exists()) { myRecAudioDir.mkdir(); } } else { mMakeTextToast("", true); } try { File f = File.createTempFile(strTempFile, ".jpg",myRecAudioDir); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f)); photoPath=f.getPath(); bm.compress(Bitmap.CompressFormat.JPEG, 80, bos); bos.flush(); bos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }}
更多相关文章
- Android热插拔事件处理流程--Vold
- Android(安卓)Robotium小结
- 【Android单元测试系列】真正的异步单元测试
- android使用notifyDataSetChanged()方法,adapter的数据更新了,但是
- android TabHost(选项卡)的使用方法
- ZWebView使用简单介绍-Android
- Win7 64位 Android(安卓)SDK下载和更新失败的解决方法
- 浅谈Java中Collections.sort对List排序的两种方法
- Python list sort方法的具体使用