-1

I want to pass the image data to another activity after taking photo or get from the gallery. But I got this error 'FAILED BINDER TRANSACTION', so I did some research and i think it's because the file size to big, I need to compress it and decompress in another activity. But the decompress code seem not working, the image is pixelated and blur.

Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

Why? How to fix it?

First Activity

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    inputStreamImg = null;

    if (resultCode == getActivity().RESULT_OK && data != null) {
        if (requestCode == PICK_IMAGE_CAMERA) {
            try {
                Uri selectedImage = data.getData();
                bitmap = (Bitmap) data.getExtras().get("data");
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.JPEG, 0, bytes);
                byte[] byteArray = bytes.toByteArray();
                goProgressDetailPage(byteArray);

            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (requestCode == PICK_IMAGE_GALLERY) {
            Uri selectedImage = data.getData();

            if (selectedImage==null){
                return;
            }

            try {
                bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), selectedImage);
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.JPEG, 0, bytes);
                byte[] byteArray = bytes.toByteArray();
                goProgressDetailPage(byteArray);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

public void goProgressDetailPage(byte[] byteArray){
    Intent i = new Intent(getContext(), EditProgressActivity.class);
    i.putExtra("viewString",byteArray);
    getContext().startActivity(i);
}

Second Activity

byte[] bytes = intent.getByteArrayExtra("viewString");
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
//decompress fail, the image is blur
base64img = Base64.encodeToString(bytes, Base64.DEFAULT);
Log.d("image uploaded", ""+base64img);
//upload base64 to server...

Related Question:

https://stackoverflow.com/questions/3528735/failed-binder-transaction-when-putting-an-bitmap-dynamically-in-a-widget#=

Still get error FAILED BINDER TRANSACTION although have compressed it

Lester
  • 701
  • 1
  • 9
  • 47

1 Answers1

0

As you said,

You need to pass the image after capturing it.So, the concept is that you just take the photo and save it to your device and get the path of the image location.Now just pass the path throughout your activities.

As per your need you do not have to compress or decompress the image.

Selvin
  • 6,598
  • 3
  • 37
  • 43
Sana
  • 456
  • 3
  • 9
  • `Uri selectedImage = data.getData();` pass this? – Lester Sep 05 '18 at 09:55
  • do you have any tutorial or reference about save the image and decode the path to bitmap? – Lester Sep 05 '18 at 10:29
  • You can try this.I think this will solve your issue though I have used compress method now. Uri mUri = getImageUri(getApplicationContext(), mImage); public Uri getImageUri(Context inContext, Bitmap mImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); mImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = Images.Media.insertImage(inContext.getContentResolver(), mImage, "ImageTitle", null); return Uri.parse(path); } Use this code to decode the path from image bitmap. – Sana Sep 05 '18 at 10:49