vinothp
vinothp

Reputation: 10059

How to Pass camera image from one intent to other intent in android?

I am trying to send camera image from one intent to another intent to display. Currently i am trying using the following method,

Once the image captured

     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  

     super.onActivityResult(requestCode, resultCode, data);  
     switch(requestCode)
     {
         case CAMERA_RECEIPTREQUEST:  
         if(resultCode== Activity.RESULT_OK)
         {
         BitmapFactory.Options options = new BitmapFactory.Options();
         options.inSampleSize = 8;
         //ImageView jpgView = (ImageView)findViewById(R.id.imageView1);
         Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);  

         Intent imagepass = new Intent(Activity1.this,Activity2.class);
         imagepass.putExtra("imagepass", imagepass);
         startActivity(imagepass);

In second activity

      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.receiptreview);   
        //creating view ids
        createViewIds();  

        Bitmap receiptimage = (Bitmap) getIntent().getExtras().getParcelable("imagepass");
        receipt.setImageBitmap(receiptimage); 
    } 

But it shows StackOverFlow error,

        at java.util.HashMap$EntrySet.iterator(HashMap.java:944)
        at android.os.Parcel.writeMapInternal(Parcel.java:486)
        at android.os.Bundle.writeToParcel(Bundle.java:1552)
        at android.os.Parcel.writeBundle(Parcel.java:502)
        at android.content.Intent.writeToParcel(Intent.java:5477)

I am not sure whether i am trying wrong method.I am looking for some sample or solution to this.

Thank for your help guys.

Upvotes: 0

Views: 3559

Answers (3)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132982

use

         Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);  

         Intent imagepass = new Intent(Activity1.this,Activity2.class);
         imagepass.putExtra("imagepass", receipt );
         startActivity(imagepass);

instead of

        Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);  

         Intent imagepass = new Intent(Activity1.this,Activity2.class);
         imagepass.putExtra("imagepass", imagepass);
         startActivity(imagepass);

You are passing Intent instance imagepass in imagepass.putExtra("imagepass", imagepass); so pass Bitmap instance in imagepass.putExtra("imagepass", receipt );

EDIT:

for passing images (bitmaps) between activities in android see these posts:

how do you pass images (bitmaps) between android activities using bundles?

How can I pass a Bitmap object from one activity to another

Upvotes: 3

Aryan
Aryan

Reputation: 67

we can try another way to convert the image to byte array and then pass the byte array through intent and in the activity being called we can convert the byte array into bitmap

Upvotes: 0

James Michael Lucas
James Michael Lucas

Reputation: 142

From what I can see your passing the intent itself to be send. Try:

imagepass.putExtra("imagepass", receipt);

Might work, still new to android myself.

Upvotes: 0

Related Questions