Thursday, 19 March 2015

Pass Bitmap Data Between Activities in Android

Pass Bitamp as Extended Data

ByteArrayOutputStream bStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, bStream);
    byte[] byteArray = bStream.toByteArray();

    Intent anotherIntent = new Intent(this, anotherActivity.class);
    anotherIntent.putExtra("image", byteArray);
    startActivity(anotherIntent);
    finish();

Retrieve Bitmap in Other Activity

Bitmap bmp;

    byte[] byteArray = getIntent().getByteArrayExtra("image");
    bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

No comments:

Post a Comment