Android - Intent 傳送 Bitmap

摘要:Android - Intent 傳送 Bitmap


ByteArrayOutputStream bs = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,100,bs);

Intent i = new Intent(context, ShowActivity.class); 
i.putExtra(EXTRA_BTYEARRAY, bs.toByteArray());

context.startActivity(i);

 

ShowActivity 頁面


ImageView ivImg = (ImageView)findViewById(R.id.iv_img );

Intent intent = getIntent();

byte[] b = intent.getByteArrayExtra(EXTRA_BTYEARRAY);
Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
ivImg .setImageBitmap(bmp);