【问题标题】:Pass Bitmap to another activity but getting error FAILED BINDER TRANSACTION将位图传递给另一个活动,但出现错误 FAILED BINDER TRANSACTION
【发布时间】:2015-06-29 12:04:04
【问题描述】:

你好朋友我想将位图从一个活动传递到另一个活动。我成功地做到了,但我的问题是当位图传递给另一个活动时,它给出了 FAILED BINDER TRANSACTION 的错误。请朋友们帮我解决这个问题。 我正在使用下面的代码将图像传递给另一个活动

     Uri selectedImageUri = data.getData();

       if(selectedImageUri!=null){

                selectedImagePath = getPath(selectedImageUri);
                Intent i = new Intent(MainActivity.this, ImageCropperActivity.class);
                i.putExtra("mpath", selectedImagePath);
                startActivity(i);

我得到这样的位图。

 if(imagePath != null){
        //Toast.makeText(getApplicationContext(), "image path " +imagePath, Toast.LENGTH_LONG).show();
        //imgCrop.setImageBitmap(BitmapFactory.decodeFile(imagePath));
        mImageUri = Uri.parse(getIntent().getStringExtra("mpath"));
        mFileTemp = new File(getIntent().getStringExtra("mpath"));
    }

请朋友们帮我解决这个问题。

【问题讨论】:

  • 此代码未传递位图。它正在传递一个Uri。虽然传递位图可能会因大小而成为问题,但 Uri 应该不是问题。 Intent 的大小有大约 1 MB 的限制,包括其附加内容。

标签: android bitmap


【解决方案1】:

尝试先压缩位图,然后将其传递给下一个活动

用这个压缩

 ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] bytes = stream.toByteArray(); 
    setresult.putExtra("BMP",bytes);

使用此代码解压缩

 byte[] bytes = data.getByteArrayExtra("BMP");
    Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

---注意---

There are some limitations as to how much data a bundle can contain. If your bundle or intent extras are too large you can get FAILED BINDER TRANSACTION error.

希望对你有帮助。

【讨论】:

  • 您好 imtiyaz 先生,这里的数据是指 Bundle 的对象?
猜你喜欢
  • 1970-01-01
  • 2014-08-08
  • 2016-04-05
  • 2015-07-16
  • 2014-10-20
  • 1970-01-01
  • 1970-01-01
  • 2011-10-17
  • 2016-01-15
相关资源
最近更新 更多