This is just ridiculous..I m trying to develop image application. What problem i am getting is: on button click i m going to gallery and on picking up the picture, I m setting that image in the image view which is in the same intent. Now on button click(like continue), I want to send that image to another activity having image view. I am new to android and i don't know that. I am rubbing my head from few days. So please any one help me out to get out of this..Thanks in advance. And also support me to got that image to be in full screen on another activity..
-
go to this:[http://stackoverflow.com/questions/17878407/send-image-from-one-activity-to-another?rq=1](http://stackoverflow.com/questions/17878407/send-image-from-one-activity-to-another?rq=1) – M D Feb 24 '14 at 05:51
4 Answers
Try below code.
For taking image from first activity, try this code
imageView.buildDrawingCache();
Bitmap bitmap = imageView.getDrawingCache();
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("BitmapImage", bitmap);
Here replace imageView
with your imageview's id.
and in other activity just write this code to get image from first activity.
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");

- 5,234
- 7
- 36
- 84
-
-
-
-
See just pass first code that is `Bitmap bitmap = imageView.getDrawingCache(); Intent intent = new Intent(this, NewActivity.class); intent.putExtra("BitmapImage", bitmap);` in your continue button. and then other code that is `Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");` to second activity. Why you need any tutorial. – InnocentKiller Feb 24 '14 at 05:53
-
-
@Nimeshjani, try this out still if you find any problem, ask me. I will help you. – InnocentKiller Feb 24 '14 at 06:03
-
-
then please accept the answer by clicking right below my answer. – InnocentKiller Feb 24 '14 at 18:10
-
do you have any idea for converting image to grid after giving rows and columns from user defined..?? – Nimesh jani Feb 24 '14 at 18:10
-
Okay, unless you absolutely have to, and the image is very small, don't send the image itself via Intent
. You should already be receiving the image URI from the Gallery Intent. Just pass that URI along as an extra in the Intent you use to launch the new Activity, and then use that to call setImageURI()
on the ImageView in that Activity.

- 133,643
- 45
- 263
- 274
When you are sending your image from one Activity to another Activity you should convert your Bitmap object to byte[] Arary and then send it.
Just Like,
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourbitmapObjectName.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Intent n = new Intent();
n.setClass(getApplicationContext(), MainActivity.class);
n.putExtra("picture", byteArray);
startActivity(n);
Now just retrieve in your Second Activity on oncreate() method.
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
if (bmp != null) {
selected.setImageBitmap(bmp);
}

- 18,895
- 5
- 32
- 63
Agree with @kcoppock, dont pass image via intent. As you may recieve a !!!Fail to deliver!!!
error on intent passing. This would occur due to memory and heap limitaions.
So you can solve problem as said by @kcoppock; by using the image URI from the gallery. And then use decodeResources
of BitmapFactory
and use the image.
Else you can use the Getter
and Setter
method in the previous activity and then access the image in other activity via Getters
method.

- 1,290
- 12
- 25