andorid 报错bindertransation

原因是 官方规定intent传递时,数据不能超过1M

The Binder transaction buffer has a limited fixed size, currently 1Mb, which is shared by all transactions in progress for the process. (http://developer.android.com/intl/zh-cn/reference/android/os/TransactionTooLargeException.html)

所以必须对图进行缩放处理

private Bitmap zoombitmap(Bitmap tmpBitmap) {
		int rawHeight = tmpBitmap.getHeight(); 
    	int rawWidth = tmpBitmap.getWidth(); 
    	System.out.println("原图高:"+rawHeight+"宽:"+rawWidth);
    	// 设定图片新的高宽,根据图片长宽进行设置 缩略图长宽
    	int newHeight=100;
    	int newWidth=200;
    	// 计算缩放因子 
    	float heightScale = ((float) newHeight) / rawHeight; 
    	float widthScale = ((float) newWidth) / rawWidth; 
    	// 新建立矩阵 
    	Matrix matrix = new Matrix(); 
    	matrix.postScale(heightScale, widthScale); 
    	 Bitmap resizeBmp =Bitmap.createBitmap(tmpBitmap,0,0,rawWidth,rawHeight,matrix,true);
    	return resizeBmp; 
		
		}

这样处理后,报错是不会了,但是不够智能,美观,需改进。

下面进行改进:

后来经过测试发现

缩小成为100*200(bitmap大小算法:100*200*4字节=78.125KB)的能成功

缩小成为200*400(312.5KB)的能成功

缩小成为250*500(488KB)的能成功

缩小成为300*500(585KB)的失败

缩小成为300*600(703KB)的失败

发现用intent的extra传bitmap最大是488+KB,所以每张图片把他按比例缩小到488KB

做点补充:直接用intent来传bitmap可能效率不高,(现在我考虑到的是界面复用问题),到时候优化可以考虑直接传一个uri过去,然后直接在界面中取图片,这样图片大小就没有限制了


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值