原因是 官方规定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过去,然后直接在界面中取图片,这样图片大小就没有限制了