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,如需转载请自行联系原作者





相关文章
|
8月前
|
定位技术 API 开发工具
Android 按照步骤接入百度地图API,定位显示不了解决办法
Android 按照步骤接入百度地图API,定位显示不了解决办法
227 0
|
2月前
|
编译器 开发工具 Android开发
|
8月前
|
Android开发
android.view.WindowLeaked的解决办法
我们知道Android的每一个Activity都有个WindowManager窗体管理器,同样,构建在某个Activity之上的对话框、PopupWindow也有相应的WindowManager窗体管理器。
62 0
|
8月前
|
Android开发
Android 使用DataBinding时 将布局页面转换为数据绑定布局(Convert to data binding layout) 不出现提示解决办法
Android 使用DataBinding时 将布局页面转换为数据绑定布局(Convert to data binding layout) 不出现提示解决办法
90 0
|
8月前
|
Android开发
Android中使用Tortoise SVN遇到代码被锁定的解决办法
Android中使用Tortoise SVN遇到代码被锁定的解决办法
74 0
|
11月前
|
监控 开发工具 Android开发
AMD机器:Android Studio启动模拟器提示“HAXM is not installed”的解决办法
AMD机器:Android Studio启动模拟器提示“HAXM is not installed”的解决办法
1510 0
|
编解码 机器人 Android开发
Android10.0 OTA 错误解决办法(@/cache/recovery/block.map‘ failed)
Android10.0 OTA 错误解决办法(@/cache/recovery/block.map‘ failed)
451 0
|
Java Android开发 开发者
Android9.0 无锁屏下连续锁屏-解屏2次,画面点击无响应 bug 解决办法
Android9.0 无锁屏下连续锁屏-解屏2次,画面点击无响应 bug 解决办法
101 0
|
Android开发
Permission failure: android.permission.CAPTURE_AUDIO_OUTPUT 解决办法
Permission failure: android.permission.CAPTURE_AUDIO_OUTPUT 解决办法
289 0
|
Android开发
Android 裁剪摄像头预览窗口-SurfaceView
Android 裁剪摄像头预览窗口-SurfaceView
538 0
Android 裁剪摄像头预览窗口-SurfaceView