`
zhy20045923
  • 浏览: 153374 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

[转载]Android大图裁剪解决办法

阅读更多
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;
}
下面是整理好的Demo,包括拍照和从相册中选择。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics