-1

I'am trying convert Byte Array to Bitmap to show in imageView in android, I am taking byte data from method but When I run the below function,I am taking null value of Bitmap, how can I take bitmap value from byte[] array

 private CameraProxy.CameraDataCallBack callBack = new CameraProxy.CameraDataCallBack() {

        @Override
        public void onDataBack(byte[] data, long length) {
            // TODO Auto-generated method stub
            Log.i(TAG, "length . " + length);

            Log.i("data",""+data);

            Bitmap bitmap = BitmapFactory.decodeByteArray(data,0,data.length);
            im.setImageBitmap(bitmap);




        }
    };
7
  • what's CameraProxy.CameraDataCallBack? Commented Dec 12, 2018 at 11:25
  • it sdk of my sensor returning code When taking pictures Commented Dec 12, 2018 at 11:26
  • is it the sdk public? are you sure that the byte array is argb? Commented Dec 12, 2018 at 11:28
  • you can't convert just any byte array to bitmap. Are you sure that byte[] data is a bitmap byte array? Commented Dec 12, 2018 at 11:29
  • 1
    how can understand that, it returns me like this "data:{88,84,83,80,82,81, + 1382390 more}" Commented Dec 12, 2018 at 11:31

1 Answer 1

0

These code works for me.

            bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),                       
            selectedImage);

            img = findViewById(R.id.imageView);

            //img.setImageBitmap(bitmap);

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byteArray = stream.toByteArray();
Sign up to request clarification or add additional context in comments.

1 Comment

you are doing exactly opposite of what being asked.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.