android activity传递图片bitmap
注:bitmap手动释放
ActivityA.class 传递
Intent intent = new Intent(XiaoListActivity.this, QupeiyinActivity.class); intent.putExtra("mCurrentPlayImageURL", mCurrentPlayImageURL); Bitmap image = ((BitmapDrawable) jiecao_video.thumbImageView.getDrawable()).getBitmap(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] bitmapByte = baos.toByteArray(); intent.putExtra("bitmap", bitmapByte); startActivity(intent);
ActivityB.class 接收
if (getIntent().getByteArrayExtra("bitmap") != null) { byte[] bis = getIntent().getByteArrayExtra("bitmap"); Bitmap bitmap = BitmapFactory.decodeByteArray(bis, 0, bis.length); sv_fengmian.setImageBitmap(bitmap); LogUtils.e("封面"+bitmap); Glide.with(QupeiyinActivity.this) .load(bitmap) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .into(sv_fengmian); }else { LogUtils.e("封面"+mCurrentPlayImageURL); Glide.with(QupeiyinActivity.this) .load(mCurrentPlayImageURL) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .into(sv_fengmian); }