android调用系统图片剪裁,兼容小米
public void cropPhoto(Uri uri) {Intent intent = new Intent("com.android.camera.action.CROP");intent.setDataAndType(uri, "image/*");// crop为true是设置在开启的intent中设置显示的view可以剪裁intent.putExtra("crop", "true");// aspectX aspectY 是宽高的比例intent.putExtra("aspectX", 1);intent.putExtra("aspectY", 1);// outputX,outputY 是剪裁图片的宽高intent.putExtra("outputX", 300);intent.putExtra("outputY", 300);/*** 此方法返回的图片只能是小图片(sumsang测试为高宽160px的图片)* 故只保存图片Uri,调用时将Uri转换为Bitmap,此方法还可解决miui系统不能return data的问题*///intent.putExtra("return-data", true);//裁剪后的图片Uri路径,uritempFile为Uri类变量uritempFile = Uri.parse("file://" + "/" + Environment.getExternalStorageDirectory().getPath() + "/" + "small.jpg");intent.putExtra(MediaStore.EXTRA_OUTPUT, uritempFile);intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());startActivityForResult(intent, PHOTO_CUT);
}
这样调用系统时完全没问题了,小米的return-data也解决了。但是调用系统照相后马上调用剪裁报错打不开图片。
测试多个机型都行,就是小米的不行。
最后发现问题。这里的uri必须是content:// 的uri file:// 的uri是不行的。
必须转换一下就行了。
另附上fiel Uri 转换成 content Uri的代码
public static Uri getImageContentUri(Context context, File imageFile) {String filePath = imageFile.getAbsolutePath();Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,new String[]{MediaStore.Images.Media._ID},MediaStore.Images.Media.DATA + "=? ",new String[]{filePath}, null);if (cursor != null && cursor.moveToFirst()) {int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));Uri baseUri = Uri.parse("content://media/external/images/media");return Uri.withAppendedPath(baseUri, "" + id);} else {if (imageFile.exists()) {ContentValues values = new ContentValues();values.put(MediaStore.Images.Media.DATA, filePath);return context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);} else {return null;}}
}
android调用系统图片剪裁,兼容小米相关推荐
- Android 调用系统图片浏览器
http://www.blogbus.com/java-android-logs/151611473.html 在做各种项目的时候会经常遇到需要调用系统图片查看器来查看自己需要查看的图片,因为这样就可 ...
- android调用系统图片裁切后出现黑边
转载地址:http://blog.sina.com.cn/s/blog_ac843e330101eha1.html 是这样的:我使用系统的图片浏览器,然后让它自动跳到图片裁切界面,当我们定义了返回的图 ...
- MVP模式的Android 调用系统拍照,相册,剪裁,适配到7.0,修复拍照图片旋转问题
Android 调用系统拍照,相册,剪裁,适配到7.0,修复拍照图片旋转问题 直接上代码 首先添加拍照需要的权限 <uses-permission android:name="andr ...
- android安装自动打开网页,Android调用系统自带浏览器打开网页的实现方法
Android调用系统自带浏览器打开网页的实现方法 在Android中可以调用自带的浏览器,或者指定一个浏览器来打开一个链接.只需要传入一个uri,可以是链接地址. 启动android默认浏览器 在A ...
- android 调用系统播放器
今天,简单讲讲android如何调用手机自带的播放器. 昨天,从服务器下载一个AVI的视频,下载后需要进行播放,所以想调用系统自带的播放器.但是由于很少用到,所以自己当时不知道怎么写,于是在网上查找资 ...
- Android调用系统分享和指定app分享-微信朋友圈图文分享和qq分享
Android调用系统分享和指定app分享-微信朋友圈图文分享和qq分享 标签: Android系统分享QQ分享朋友圈图文分享 2016-09-27 22:54 279人阅读 评论(0) 收藏 举报 ...
- Qt Android 调用系统文件管理
1.了解 使用JNI扩展Qt应用 参考<Qt on Android核心编程>15章 源码https://download.csdn.net/download/dinosaurx/10149 ...
- Android 调用系统裁剪,适配11和12及手机
前言:发现Android 调用系统裁剪时,在各Android 版本出现各种问题,踩了一堆坑,做一下总结,免得以后忘记 后面会有完整裁剪代码 1,一加手机报错 intent.putExtra(" ...
- android 图库管理,Android调用系统图库
上面一篇讲到Android调用系统相机时遇到的兼容性问题,没想到选择系统图库的时候竟然也遇到了系统兼容性问题,在这里记录下解决方案吧. 首先是调用系统默认图库代码: Intent intent = n ...
最新文章
- ie下input的type属性为hidden问题
- 有了这篇 Shell 脚本实践指南,同事对我“刮目相看”!
- oracle实现自增字段
- SVG 动画实现弹性的页面元素效果
- 提高mysql insert速度_让你的insert操作速度增加1000倍的方法
- [cdq分治][树状数组] Jzoj P4419 hole
- datax 定时执行多个job_DataX在有赞大数据平台的实践
- IOS机型margin属性无效问题
- 如何给UNIX域Socket套接字抓包?
- 根据xml文件生成对应javabean类
- maven clean警告:The requested profile “pom.xml“ could not be activated because it does not exist
- 接口自动化测试系列之PHPUnit-POST请求接口测试方法
- System Verilog——任务和函数 Part-I
- 原生 遍历_ECMAScript 6 入门教程—异步遍历器
- 蓝牙耳机测试软件apk_延迟测试app下载-蓝牙耳机延迟测试软件下载v1.9.1- 游侠下载站...
- bum报文_数据中心VxLAN技术概念和原理解读
- ppt太大怎么变小,ppt如何压缩变小
- cpu_scale/max_freq_scale/cpu_capacity/cpu_capacity_orig的含义
- lisp 左手钢筋_CAD左手键及使用方法
- 渗透测试成功的8个关键