1

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..

Nimesh jani
  • 23
  • 2
  • 7
  • 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 Answers4

1

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");
InnocentKiller
  • 5,234
  • 7
  • 36
  • 84
1

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.

Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
1

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);

   }
Piyush
  • 18,895
  • 5
  • 32
  • 63
0

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.

BlueSword
  • 1,290
  • 12
  • 25