0

I want to set the Image to be Selected from the Android Gallery. I use this code to get selected Image.

Intent intent = new Intent(); 
intent.setType("image/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT);// 
//startActivity(intent);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),10);

And the onActivityResult Method is like:

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {     
        super.onActivityResult(requestCode, resultCode, data);     
        if (requestCode == 10 && resultCode == Activity.RESULT_OK) {             
            Uri contentUri = data.getData();          
            String[] proj = { MediaStore.Images.Media.DATA };         
            Cursor cursor = managedQuery(contentUri, proj, null, null, null);         
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);         
            cursor.moveToFirst();         
            String tmppath = cursor.getString(column_index);           
            Bitmap croppedImage = BitmapFactory.decodeFile(tmppath);
            go.setVisibility(View.VISIBLE);
            //canvas.drawBitmap(kangoo, 130, 100, null);
            //previewImage.setVisibility(View.VISIBLE);

            imageSrc.setImageBitmap(croppedImage);    //set to your imageview          
        }
}

Now, I want to select Image from the gallery and send it to another activity. So how it is Possible with above code ?? Thanks.

Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188

3 Answers3

4

You can pass the URI of the Image to next Activity.

the URI which you get from onActivityResult()

and in onCreate() of the next Activity.

Decode the Bitmap again and set it to ImageView

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
1

passing the Image from one activity to another was too much expensive rather than you can pass it's image path as string and load.

see this post

Community
  • 1
  • 1
Pratik
  • 30,639
  • 18
  • 84
  • 159
0

in OnActivityResult

Intent intent = new Intent(Activity1.this,Activity2.class);
intent.putExtra("bmp",croppedImage);
startActivity(intent);

Second Activity

Bitmap bmp = this.getIntent().getParcelableExtra("bmp");
MKJParekh
  • 34,073
  • 11
  • 87
  • 98