Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Create a Bitmap from byte[]. Received Data. #72

Closed
rafaelcrz opened this issue Apr 11, 2017 · 1 comment
Closed

Create a Bitmap from byte[]. Received Data. #72

rafaelcrz opened this issue Apr 11, 2017 · 1 comment

Comments

@rafaelcrz
Copy link

User 1 takes a photo from camera, get it and send to other user.

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                Bundle bundle = data.getExtras();
                Bitmap bitmap = (Bitmap) bundle.get("data");

                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
                byte[] bitmapByte = outputStream.toByteArray();

                bluetoothSPP.send(bitmapByte, true); **//Send the Bitmap array**
            }
        }

User 2 receive the Bitmap byte[].

 bluetoothspp.setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() {
            public void onDataReceived(byte[] data, String message) {

                Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                Glide.with(ChatActivity.this).load(bitmap ).asBitmap().into(imgFundo); //Use Glide for show Bitmap
            }
    });

But I always get an error and Glide can not display the image.
I did a debug and the data comes in several parts, like an array of bytes.

  • How can I build a Bitmap from data received?

Thanks

@bhorgaurav
Copy link

Does onActivityResult.bitmapByte.length match setOnDataReceivedListener.data.length ? If not, that's your issue. The data might be fragmented.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants