1

I want to pass captured camera image and select image from gallery, image should be display in next activity for captured image my code is working fine..but select image from gallery the image is not displaying in the activity..

First Activity

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
     if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_CAMERA) {

            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            //file path of captured image
            imagepath = cursor.getString(columnIndex); 
            //file path of captured image
            File f = new File(imagepath);
            String filename = f.getName();

            /*Toast.makeText(Contact.this, "Your Path:"+imagepath, 2000).show();
            Toast.makeText(Contact.this, "Your Filename:"+filename, 2000).show();*/
            cursor.close();
            //Log.i("image path", imagepath);
            Bitmap imageData = BitmapFactory.decodeFile(imagepath);
            // Bitmap imageData = null;
             imageData = (Bitmap) data.getExtras().get("data");

             Intent i = new Intent(this, Cam.class);
             i.putExtra("name", imageData );
             startActivity(i);
            //imageview.setImageBitmap(bit);
        }



        else if (requestCode == SELECT_FILE) {
                //Bitmap photo = (Bitmap) data.getData().getPath(); 

                Uri selectedImageUri = data.getData();
                imagepath = getPath(selectedImageUri, null);

                 // your bitmap
                //ByteArrayOutputStream bs = new ByteArrayOutputStream();
                Bitmap imageData = BitmapFactory.decodeFile(imagepath);                                                                                               
                imageData = (Bitmap) data.getExtras().get("data");
                Intent intent = new Intent(this, Cam.class);
                intent.putExtra("name", imageData );
                 startActivity(intent);

Second Activity

protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.cam);

      Bitmap bitmap  = getIntent().getExtras().getParcelable("name");
        ImageView view = (ImageView) findViewById(R.id.imageView1);
        view.setImageBitmap(bitmap); 



        }
sandy
  • 53
  • 1
  • 10

5 Answers5

0
Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImage", bitmap);

and retrieve it on the other end:

Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
Piyush
  • 18,895
  • 5
  • 32
  • 63
Santosh Kathait
  • 1,444
  • 1
  • 11
  • 22
0

To start another activity and receive a result back call startActivityForResult() (instead of startActivity()).

In the startActivityForResult pass the image URI and the next context.

I think this should be enough in your scenario.

lapadets
  • 1,067
  • 10
  • 38
0

You can use bundle to pass to another activity.

Shriram
  • 4,343
  • 8
  • 37
  • 64
0

If the image in your device, you can pass path of the image. Than display from path.

MSr
  • 288
  • 1
  • 6
  • 14
0

Use this.

Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("path", imagepath);

in your next Activity retrieve as

String image_path = getIntent().getStringExtra("path");
Bitmap bitmap = BitmapFactory.decodeFile(image_path);
imageview.setImageBitmap(bitmap);
Piyush
  • 18,895
  • 5
  • 32
  • 63
  • still it didnt show preview..it shows error... Activity com.sec.android.gallery3d.app.Gallery has leaked IntentReceiver com.sec.samsung.gallery.view.albumview.AlbumViewState$21@42a874c0 that was originally registered here. Are you missing a call to unregisterReceiver()? 03-11 18:31:15.392: E/ActivityThread(12570): android.app.IntentReceiverLeaked: Activity com.sec.android.gallery3d.app.Gallery has leaked IntentReceiver com.sec.samsung.gallery.view.albumview.AlbumViewState$21@42a874c0 that was originally registered here. Are you missing a call to unregisterReceiver()? – sandy Mar 11 '14 at 13:02
  • :thank u its working fine but i want to display both camera/gallery image in imageview when gallery image is displaying..camera captured image is not working ..please help.. – sandy Mar 12 '14 at 04:59
  • have you make imaepath string global? – Piyush Mar 12 '14 at 05:00
  • yes i have declared imagepath global ....How to put one view for both in the second class – sandy Mar 12 '14 at 05:03