activity间传送bitmap的办法

Aactivity.class
     <span style="white-space:pre">		</span>    Drawable mDrawable = imageView.getDrawable();
                    Bitmap bitmap = ((BitmapDrawable) mDrawable).getBitmap();
                    Bundle bundle = new Bundle();
                    bundle.putParcelable("bitmap", bitmap);
                    Intent intent = new Intent(this, PhotoActivity.class);
                    intent.putExtra("bundle", bundle);
                    startActivity(intent);

PhotoActivity.class

        intent = getIntent();
        Bundle bundle=intent.getBundleExtra("bundle");
        Bitmap bitmap=bundle.getParcelable("bitmap");
        imageview.setImageBitmap(bitmap);

但是上面方法传送的不多,还有一种办法:

 
  
  
Aactivity.class

<span style="white-space:pre">		</span>Intent intent = new Intent(getActivity(), Aactivity.class);
                Drawable mDrawable=imageview.getDrawable();
                Bitmap bitmap=((BitmapDrawable) mDrawable).getBitmap();
                ByteArrayOutputStream bs = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
                intent.putExtra("byteArray", bs.toByteArray());
                startActivity(intent);

PhotoActivity.class

if(getIntent().hasExtra("byteArray")) {
            Bitmap b = BitmapFactory.decodeByteArray(
                    getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);
            imageview.setImageBitmap(b);
        }

上面的方法还是有限制的。
如果你使用的是ImageLoader的话,那就应该用起来它的缓存功能.

  
   
   
ImageLoader.getInstance().displayImage(imageUri,imageView);
String key=DiskCacheUtils.findInCache(imageUri,ImageLoader.getInstance().getDiskCache()).getPath();

otherActivityImageView.setImageURI(Uri.parse(key));
如果一定要传送bitmap的话,其实就是应该把bitmap缓存起来。



猜你喜欢

转载自blog.csdn.net/Ser_Bad/article/details/51007887