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:
Still get error FAILED BINDER TRANSACTION although have compressed it