Android大图裁剪解决办法

简介:

 某些功能需要拍照或者从相册选择照片后经过裁剪再上传的时候,

cropimage

cropimage

可以调用手机自带的com.android.camera.action.CROP这个Intent进行裁剪
通过设置输出大小可以得到图片的大小:
intent.putExtra(“outputX”, outputX);
intent.putExtra(“outputY”, outputY);
但是当outputX或者outputY 大小设置为320以上的时候,会发现完全没有效果。
通过搜索才发现了这个问题原来是这样的:
Mobile devices typically have constrained system resources.
Android devices can have as little as 16MB of memory available to a single application.
在Android2.3中,默认的Bitmap为32位,类型是ARGB_8888,
也就意味着一个像素点占用4个字节的内存。3200*2400*4 bytes = 30M。
消耗这样大的内存当然不可能实现。

看看com.android.camera.action.CROP这个Intent可以设置的参数:

crop_params
data和MediaStore.EXTRA_OUTPUT都是可选的传入数据选项,可以选择设置data为Bitmap,或者将相应的数据与URI关联起来,
你也可以选择是否返回数据(return-data: true)。

使用return Bitmap的话有限制不能太大,那么如果要裁剪大图的话只能使用URI这个参数了。
public Intent getCropImageIntent() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType(“image/*”);
intent.putExtra(“crop”, “true”);
intent.putExtra(“aspectX”, 1);
intent.putExtra(“aspectY”, 1);
intent.putExtra(“outputX”, 600);
intent.putExtra(“outputY”, 600);
intent.putExtra(“noFaceDetection”, true);
intent.putExtra(“scale”, true);
intent.putExtra(“return-data”, false);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
intent.putExtra(“outputFormat”, Bitmap.CompressFormat.JPEG.toString());
return intent;
}

源码下载地址:http://06peng.com/archives/192





     本文转自06peng 51CTO博客,原文链接:http://blog.51cto.com/06peng/1100029,如需转载请自行联系原作者





相关文章
|
定位技术 API 开发工具
Android 按照步骤接入百度地图API,定位显示不了解决办法
Android 按照步骤接入百度地图API,定位显示不了解决办法
361 1
|
1月前
|
Android开发
Android中SurfaceView的双缓冲机制和普通View叠加问题解决办法
本文介绍了 Android 平台上的 SurfaceView,这是一种高效的图形渲染控件,尤其适用于视频播放、游戏和图形动画等场景。文章详细解释了其双缓冲机制,该机制通过前后缓冲区交换来减少图像闪烁,提升视觉体验。然而,SurfaceView 与普通 View 叠加时可能存在 Z-Order 不一致、同步问题及混合渲染难题。文中提供了使用 TextureView、调整 Z-Order 和创建自定义组合控件等多种解决方案。
82 9
|
4月前
|
Android开发
Android studio 出现Plugin [id: ‘com.android.application‘, version: ‘8.1.0‘, apply: false] 问题解决办法
Android studio 出现Plugin [id: ‘com.android.application‘, version: ‘8.1.0‘, apply: false] 问题解决办法
798 1
|
4月前
|
Android开发 Windows
android studio开发时提示 TLS 握手错误解决办法
在Windows环境下遇到TLS协议版本不支持的错误,Gradle构建失败。解决方案是在build.gradle.kts中设置系统属性`https.protocols`为`TLSv1.2`,而非遵循误导信息设置为TLSv1.1。
|
5月前
|
编译器 开发工具 Android开发
|
Android开发
android.view.WindowLeaked的解决办法
我们知道Android的每一个Activity都有个WindowManager窗体管理器,同样,构建在某个Activity之上的对话框、PopupWindow也有相应的WindowManager窗体管理器。
122 0
|
5月前
|
XML 算法 Java
Android App开发之位图加工Bitmap中转换位图的像素色彩、裁剪内部区域、利用矩阵变换位图的讲解及实战(附源码和演示)
Android App开发之位图加工Bitmap中转换位图的像素色彩、裁剪内部区域、利用矩阵变换位图的讲解及实战(附源码和演示)
75 0
|
Android开发
Android 使用DataBinding时 将布局页面转换为数据绑定布局(Convert to data binding layout) 不出现提示解决办法
Android 使用DataBinding时 将布局页面转换为数据绑定布局(Convert to data binding layout) 不出现提示解决办法
147 0
|
Android开发
Android中使用Tortoise SVN遇到代码被锁定的解决办法
Android中使用Tortoise SVN遇到代码被锁定的解决办法
109 0
|
监控 开发工具 Android开发
AMD机器:Android Studio启动模拟器提示“HAXM is not installed”的解决办法
AMD机器:Android Studio启动模拟器提示“HAXM is not installed”的解决办法
2695 0