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

一旦图像捕获

     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)

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

谢谢你们的帮助,伙计们。

有帮助吗?

解决方案

使用方法

         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中的活动之间传递图像(位图),请参阅这些帖子:

如何使用bundle在android活动之间传递图像(位图)?

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

其他提示

从我可以看到你的意图本身被发送。尝试:

imagepass.putExtra("imagepass", receipt);
.

可能工作,仍然是android自己的新手。

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top