I want to send and receive image between the two activity using
Intent intent = new Intent(this, second.class)
in Android.
Asked
Active
Viewed 586 times
0

Vadim Kotov
- 8,084
- 8
- 48
- 62

Mohammd Qandeel
- 11
- 1
-
Pass the uri to the image as an intent extra – Tim Oct 24 '16 at 12:01
-
1refer to this link http://stackoverflow.com/a/8017425/4684984 – Multidots Solutions Oct 24 '16 at 12:02
-
Possible duplicate of [How to pass a URI to an intent?](http://stackoverflow.com/questions/8017374/how-to-pass-a-uri-to-an-intent) – Vadim Kotov Oct 26 '16 at 14:28
1 Answers
0
first you have to convert the image in byte array
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
send byte array through intent
Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("picture", byteArray);
startActivity(intent);
Get Byte Array from Bundle and Convert into Bitmap Image:
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);

hatib abrar
- 123
- 3
- 14