调用系统相机的方式

来源:互联网 发布:js push(obj) 编辑:程序博客网 时间:2024/06/05 00:50
</pre><pre name="code" class="java"><span style="font-family:Arial;">//权限<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /></span>Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);startActivityForResult(intent, 1);

if (resultCode == Activity.RESULT_OK) {if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {// 检查SD是否存在Log.e("SD NULL", "SD card is not avaiable now ");} else {if (requestCode == 1) {Bundle bundle = data.getExtras();Bitmap bitmap = (Bitmap) bundle.get("data");// 获取相机返回数据File file = new File("/sdcard/image/", "1.png");if (file.exists()) {file.delete();}try {file.createNewFile();} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}// 创建文件夹OutputStream os = null;try {os = new FileOutputStream(file);bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);// (输出数据格式,写入文件质量,输出流)} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {try {os.flush();os.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}imageView.setImageBitmap(bitmap);}}}


0 0
原创粉丝点击