Activity之间传递Bitmap

 在做项目的过程中发现Bitmap不能被序列化,下面是一种能把bitmap转为字节数组进行传递的过程,记下来,备用。

//第一句是我获得我model里的bitmap

Bitmap bmp=((BitmapDrawable)list.get(position).getAppIcon()).getBitmap();
Intent intent = new Intent(context, AboutFeedBackActivity.class);
ByteArrayOutputStream baos=new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte [] bitmapByte =baos.toByteArray();

听说bitmap本身就已经序列化了,但是由于一些原因我也不能用正常的传递方法。

//接受时

byte[] bis = intent.getByteArrayExtra("bitmap");
  Bitmap bitmap = BitmapFactory.decodeByteArray(bis, 0, bis.length);
  app_info_feedback_icon.setImageBitmap(bitmap);

posted on 2014-10-28 20:17  风者之心  阅读(717)  评论(0编辑  收藏  举报

导航