0

我正在尝试将相机图像从一个意图发送到另一个意图来显示。目前我正在尝试使用以下方法,

一旦图像被捕获

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

在第二个活动

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

但它显示 StackOverFlow 错误,

        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)

我不确定我是否尝试了错误的方法。我正在寻找一些样本或解决方案。

谢谢你们的帮助。

4

3 回答 3

3

利用

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

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

代替

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

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

您正在传入 Intent 实例 imagepass,imagepass.putExtra("imagepass", imagepass);因此传入Bitmap实例imagepass.putExtra("imagepass", receipt );

编辑:

要在 android 中的活动之间传递图像(位图),请参阅这些帖子:

您如何使用捆绑包在 android 活动之间传递图像(位图)?

如何将 Bitmap 对象从一个活动传递到另一个活动

于 2012-05-18T15:20:49.580 回答
0

从我可以看到您传递要发送的意图本身。尝试:

imagepass.putExtra("imagepass", receipt);

可能有效,我自己对 android 还是新手。

于 2012-05-18T15:22:00.827 回答
0

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

于 2013-02-21T06:53:05.163 回答