Wednesday, June 12, 2013

Sending BitMap Between Activities:

Sending BitMap Between Activities:

In Activity 1 :
do like this---------------->
Which image you want to send to next activity
bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); // here imageView is an XML related image view.
       
Intent intent = new Intent(mContext, NextActivity.class);
        ByteArrayOutputStream bs = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, bs);
        intent.putExtra("byteArray", bs.toByteArray());
        startActivity(intent);


In Activity 2 :
try{
        if(getIntent().hasExtra("byteArray")) {
        bitmap = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);      
                imageView.setImageBitmap(bitmap); // here imageView Activity 2 related imageView
            }
        }catch (Exception e) {
e.printStackTrace();
}

No comments: