public class MyObject implements Parcelable{
Bitmap image;
String title;
@Override
public int describeContents() {
return 0;
}
我不明白如何制作parcelable 对了
@Override
public void writeToParcel(Parcel dest, int flags) {
}
我也使用ImageTextAdapter并将我的对象存储在ArrayList
中答案 0 :(得分:1)
将位图写入parcel:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
parcel.writeInt(byteArray.length);
parcel.writeByteArray(byteArray);
从包裹中读取位图:
int length = parcel.readInt();
byte[] byteArray = new byte[length];
parcel.readByteArray(byteArray);
image = BitmapFactory.decodeByteArray(byteArray, 0, length);