博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android 调用系统裁剪图片,提示无法保存经过裁剪的图片
阅读量:6990 次
发布时间:2019-06-27

本文共 1864 字,大约阅读时间需要 6 分钟。

  hot3.png

昨天遇到了一个问题。就是上传头像时,调用系统的裁剪图片某些手机会提示无法保存已经过裁剪的图片。

最后弄到凌晨4点半终于处理好了,4点半发了个版本出来。卧槽。。。

这里废话一句。对你现在的同事好点,不然万一他离职了,而且把注释给删了。。。。。嘿嘿,有你哭的

好了废话不多说了,说处理办法。

遇到这个问题,我发现了2个可能性。

1.有可能你保存的图片路径不对。比如

Intent intentFromCapture = new Intent( MediaStore.ACTION_IMAGE_CAPTURE);

File out = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+"head.jpg");

Uri uri = Uri.fromFile(out);

intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, uri);

startActivityForResult(intentFromCapture, FROM_CAMERA);

因为Environment.getExternalStorageDirectory().getAbsolutePath()返回的String字符串结尾是没有/的。所以你必须手动加一个这个

如果不加,那么你预期的保存地址也许是:/mnt/sdcard/head.jpg

但是你得到的却是:/mnt/sdcardhead.jpg

2.是因为某些手机兼容性的问题。android他拍照之后调用系统自带的裁剪功能,他是需要2个图片文件。一个保存拍照的图片,一个保存裁剪完成的图片。

你设置的拍照保存的文件和你裁剪之后的文件设置成了同一个文件,所以会出现这个问题。

------------调用系统拍照

Intent intentFromCapture = new Intent( MediaStore.ACTION_IMAGE_CAPTURE);

File out = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+"head.jpg");//设置拍照保存地址

Uri uri = Uri.fromFile(out);

intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, uri);

startActivityForResult(intentFromCapture, FROM_CAMERA);

------------调用系统裁剪

Intent intent = new Intent("com.android.camera.action.CROP");

        
        intent.setDataAndType(uri, "image/*");
        intent.putExtra("output", Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+"head2.jpg")));//设置裁剪保存地址
        intent.putExtra("crop", "true");
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("outputX", cutW);
        intent.putExtra("outputY", cutH);
        intent.putExtra("scale", true);// 去黑边
        intent.putExtra("scaleUpIfNeeded", true);// 去黑边
        startActivityForResult(intent, FROM_CUT);

---------------------2015-06-08

今天尼玛客户有遇到裁剪图片提示无法加载图片的问题。草草草草草

解决方法百度到iteye的这个,经测试是可以的:http://gundumw100.iteye.com/blog/2158345

关键代码,在文章代码着色里面的101行至105行之间。

转载于:https://my.oschina.net/lin003/blog/422213

你可能感兴趣的文章
我的友情链接
查看>>
PHP Memcache扩展安装配置步骤
查看>>
携程dynamicAPK框架研究(一)
查看>>
电脑办公小技巧
查看>>
python2.7安装django报UnicodeEncodeError错误
查看>>
计算机应用专业的学生应该掌握的IT技能
查看>>
MyEclipse 编写java mail 时遇到 java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream...
查看>>
Spring Security 学习之LDAP认证
查看>>
c++适配器
查看>>
医院启用智能结构化电子病历
查看>>
Python发送各类邮件的主要方法
查看>>
nginx同一端口监听多个域名和同时监听http,https
查看>>
关于win7系统的设置文件共享与远程连接的步骤整理
查看>>
每天一个linux命令(11):nl命令
查看>>
Apache2.2+tomcat负载均衡session共享配置说明手册1.1版
查看>>
PHP 5.3.0以上推荐使用mysqlnd驱动
查看>>
vue.js中使用d3.js画家谱关系图
查看>>
python实现跨文件全局变量的方法
查看>>
grails的那个编码,老是忘记,记这里。。。。。
查看>>
禁用arcgis security service
查看>>