Advertisement
Guest User

Bitmap

a guest
Jul 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. case STATE_MESSAGE_RECEIVED_IMAGE:
  2.                         //------------convert ByteArray to Bitmap-----------------//
  3.                         byte[] readBuff_image= (byte[]) msg.obj;
  4.                         System.out.println(Arrays.toString(readBuff_image));
  5.                        byte [] bits = new byte[readBuff_image.length*4]; //That's where the RGBA array goes.
  6.                         int i;
  7.                         for(i=0;i<readBuff_image.length;i++)
  8.                         {
  9.                             bits[i*4] = bits[i*4+1] = bits[i*4+2] = (byte) ~readBuff_image[i]; //Invert the source bits
  10.                             bits[i*4+3] = (byte) 0xff; // the alpha.
  11.                         }
  12.  
  13. //Now put these nice RGBA pixels into a Bitmap object
  14.  
  15.                         Bitmap bm = Bitmap.createBitmap(128, 64, Bitmap.Config.ARGB_8888);
  16.                         bm.copyPixelsFromBuffer(ByteBuffer.wrap(bits));
  17.                         imageView.setImageBitmap(bm);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement