首页 > 系统 > Android > 正文

android调用系统摄像机拍照

2019-11-09 18:17:45
字体:
来源:转载
供稿:网友
调用摄像机权限:<uses-permission android:name="android.permission.CAMERA" /><uses-feature android:name="android.hardware.camera" /><uses-feature android:name="android.hardware.camera.autofocus" />文件操作权限:<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
final int OPEN_CAMERA = 1;Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");startActivityForResult(intent, OPEN_CAMERA);
@OverridePRotected void onActivityResult(int requestCode, int resultCode, Intent data) {	if (requestCode == OPEN_CAMERA){		if (resultCode == RESULT_OK) {			Bitmap bm = (Bitmap) data.getExtras().get("data");			savaBitmap(bm,Environment.getExternalStorageDirectory()+"/test.jpg");			imageview.setImageBitmap(bm);		}	}	super.onActivityResult(arg0, arg1, arg2);}bitmap保存图片:
public void savaBitmap(Bitmap bm,String filePath){	File file = new File(filePath);    try {	     BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));	     bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);	     bos.flush();	     bos.close();    } catch (Exception e) {    }}http://blog.csdn.net/guo83851250/article/details/54882380
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表