android GridView 异步加载 网络图片 怎么用Intent传递一个Bitmap数组(集合也行)?请贴出详细代码谢谢
public class ParceBean implements Parcelable{
private Bitmap dw;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Bitmap getDw() {
return dw;
}
public void setDw(Bitmap dw) {
this.dw = dw;
}
public static final Parcelable.Creator<ParceBean> CREATOR = new Creator<ParceBean>() {
public ParceBean createFromParcel(Parcel source) {
ParceBean pb = new ParceBean();
pb.name = source.readString();
pb.dw = Bitmap.CREATOR.createFromParcel(source);
return pb;
}
public ParceBean[] newArray(int size) {
return new ParceBean[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeString(name);
dw.writeToParcel(parcel, 0);
}
}
传递:
ParceBean[] listBitmap = new ParceBean[picUrlArr.length];
ParceBean p = new ParceBean();
for (int i = 0; i < picUrlArr.length; i++) {
ParceBean parceBean = new ParceBean();
parceBean.setDw(HttpDownload.getHttpBitmap(picUrlArr[i]));
listBitmap[i] = parceBean;
}
Intent intent = new Intent();
intent.setAction(AppConstant.PaperAction.ACTION_PAPERLAST);
Bundle bundle = new Bundle();
bundle.putParcelableArray("listBitmap", listBitmap);
intent.putExtras(bundle);
PaperLastService.this.sendBroadcast(intent);
接收:
ParceBean[] listBitmap = (ParceBean[]) bundle.getParcelableArray("listBitmap");
paperImgIv.setImageBitmap(listBitmap[0].getDw());
报错:
java.lang.RuntimeException: Error receiving broadcast Intent
怎么调试都不行 ,请高手指点,说明下,ParceBean 实现了Parcelable,传的都是小图,是接受有问题,还是发送有问题,请各位大神指教,我将不胜感激
[解决办法]
你干脆在application里面呆上图片吧
[解决办法]
//这里是图片转化成byte[];byte[] data=null;//或者直接使用Bitmap对象Bitmap bm =null;//设置图片路径 String picDirStr ="";File picDir = new File(picDirStr); if(!picDir.exists()){ picDir.mkdir(); }//设置图片名字String picName = picDirStr+"xxx.png"File myCaptureFile = new File(picName); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(myCaptureFile)); bm.compress(Bitmap.CompressFormat.JPEG, 80, bos); bos.flush(); bos.close();//在Intent 中传递图片路径就可以了Intent intent=new Intent(); intent.putExtra("src", picName);