Passing Bitmap between two activities [duplicate]

You can simply try with below –

Intent i = new Intent(this, Second.class)
i.putExtra("Image", bitmap);
startActivity(i)

And, in Second.class

Bitmap bitmap = (Bitmap) intent.getParcelableExtra("Image");

Have a look at here If you want to compress your Bitmap before sending to next activity just have a look at below –

Intent i = new Intent(this, NextActivity.class);
Bitmap b; // your bitmap
ByteArrayOutputStream bs = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 50, bs);
i.putExtra("byteArray", bs.toByteArray());
startActivity(i);

in your nextactivity –

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

Leave a Comment