Recently in the development of the need to use the image bitmap serialization and delivery, found that bitmap is not serialized, the following is the implementation of a serialization method, sharing.
The following is serialized by Byte[], because bitmap is not serialized, we need to implement it, you can choose to inherit bitmap to implement serialization, where byte[] mode is used.
You can then use Intent's Putextra (String name,parcelable value) to send the bitmap.
ImportJava.io.ByteArrayOutputStream;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.graphics.Bitmap.CompressFormat;ImportAndroid.os.Parcel;Importandroid.os.Parcelable;/***@authortcwkid* @date 2011-12-07*/ Public classDetailiconImplementsparcelable{PrivateBitmap Draw;Private Static byte[] bytedraw; PublicBitmap Getdraw () {returnDraw;} Public voidSetdraw (Bitmap draw) { This. Draw =Draw;} @Override Public intdescribecontents () {return0;} @Override Public voidWritetoparcel (Parcel dest,intflags) {Bytedraw=getBytes (Draw);d Est.writebytearray (Bytedraw);//In fact, the writing here is sequential, first-written first read} Public Static FinalParcelable.creator creator=NewCreator () {@Override PublicDetailicon[] NewArray (intsize) {return Newdetailicon[size];} @Override PublicDetailicon Createfromparcel (Parcel source) {Detailicon di=NewDetailicon (); Source.readbytearray (Bytedraw);d I.setdraw (Getbitmap (Bytedraw));returndi;}}; Private StaticBitmap Getbitmap (byte[] data) {returnBitmapfactory.decodebytearray (data, 0, data.length);} Private byte[] getBytes (Bitmap Bitmap) {bytearrayoutputstream baops=NewBytearrayoutputstream (); Bitmap.compress (Compressformat.png,0, baops);returnBaops.tobytearray ();}}
Android Bitmap Serialization