android打开系统相机分别获得原图和缩略图
2016-12-08 15:27
459 查看
第一种:获得缩略图:
打开相机
这里使用data得到的只是缩略图,大小一般30k左右,一般用在手机展示如头像这种小图,想上传图片数据到服务器就不合适了!
第二种:获得原图
打开相机
这里的f.getAbsolutePath()就是原图的路径了:
这里可能用到他的Uri数据,
由相机或图库中的图片bitmap与uri互相转换
1、bitmap to uri
2、uri to bitmap
权限:
打开相机
private void photo() { Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(openCameraIntent, TAKE_PICTURE); }
这里使用data得到的只是缩略图,大小一般30k左右,一般用在手机展示如头像这种小图,想上传图片数据到服务器就不合适了!
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { switch (requestCode) { case TAKE_PICTURE: String fileName = String.valueOf(System.currentTimeMillis()); Bitmap bm = (Bitmap) data.getExtras().get("data"); String path = FileUtils.saveBitmap(bm, fileName); if (!StringUtil.isBland(path)) { String decodePath = FileUtils.saveBitmap(UIUtils.decodeBitmap(path), "decode" + fileName); if (!StringUtil.isBland(decodePath)) { selectImagesDecodePath.add(decodePath); selectImagesPath.add(path); showAdapter(); } } break; } } super.onActivityResult(requestCode, resultCode, data); }
第二种:获得原图
打开相机
private void photo() { File dir = new File(Environment.getExternalStorageDirectory() + "/DataCollect/"); if (!dir.exists()) dir.mkdirs(); Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); localTempImg = System.currentTimeMillis(); localTempImgFileName = localTempImg + ".jpg"; File f = new File(dir, localTempImgFileName); Uri u = Uri.fromFile(f); intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0); intent.putExtra(MediaStore.EXTRA_OUTPUT, u); startActivityForResult(intent, TAKE_PICTURE); }
这里的f.getAbsolutePath()就是原图的路径了:
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { switch (requestCode) { case TAKE_PICTURE: File f = new File(Environment.getExternalStorageDirectory() + "/DataCollect/" + localTempImgFileName); LogUtils.e(f.getAbsolutePath()); if (!StringUtil.isBland(f.getAbsolutePath())) { String decodePath = FileUtils.saveBitmap(UIUtils.decodeBitmap(f.getAbsolutePath()), "decode" + localTempImg); if (!StringUtil.isBland(decodePath)) { selectImagesDecodePath.add(decodePath); selectImagesPoth.add(f.getAbsolutePath()); showAdapter(); } } break; } } super.onActivityResult(requestCode, resultCode, data); }
这里可能用到他的Uri数据,
Uri u=Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(), f.getAbsolutePath(), null, null));
由相机或图库中的图片bitmap与uri互相转换
1、bitmap to uri
Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, null,null));
2、uri to bitmap
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
权限:
<uses-permission Android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
相关文章推荐
- Android日常知识收集与总结之调用系统相机拍照,获得原图
- android调用系统相机,获得原图
- android调用系统相机拍照之获取原图和缩略图
- android 调用系统相机拍照 获取原图
- android 打开系统相机拍照并保存文件,显示图片。
- Android基础--调用系统相机,打开相册,裁剪图片并展示到界面
- Android打开系统相机、相册,并进行裁剪图片的工具类CameraUtil,以及相册获取图片注意要点。
- android 调用系统相机拍照并保存照片原图
- Android调用相机程序和图片处理程序获得原图并且进行图片处理
- Android开发获取相机拍照的原图(并非缩略图)
- android 调用系统相机拍照 获取原图
- Android启动系统相机,打开图库选择图片
- android 调用系统相机拍照 获取原图
- android 调用系统相机拍照 获取原图
- Android使用摄像头,分别获取照片的缩略图与原图
- android 手机拍照获得 缩略图 或者 获得原图
- android 调用系统相机拍照 获取原图
- android 调用系统相机拍照 获取原图
- Android 调用系统相机拍照并获取原图
- Android-打开系统相机并拍照两种显示方式。