简体   繁体   中英

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.

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

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.

我们可以尝试另一种将图像转换为字节数组,然后通过intent传递字节数组的方法,在调用活动时,我们可以将字节数组转换为位图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM