Get Byte Array Of Image From Inputstream Of Bluetooth
I want to receive a jpeg image in android from a hardware via Bluetooth . I want to read the inputstream and show the actual data from byte array. my actual data looks like: ff d8
Solution 1:
(1) How to show the actual result(hex values) in logcat?
Since you already have the byte values, you just have to format these values according to HEX base. String.format("%02X ", ...)
will do just fine:
final byte[] packetBytes = newbyte[bytesAvailable];
mmInputStream.read(packetBytes);
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append(String.format("%02X ", b)).append(" ");//there's no need to mask it with 0xFF. Don't forget to leave a " " between bytes so you may distinguish them.
}
Log.d("data: " + sb.toString());
(2) Then show the jpg image from the hex value??
If you're sure those bytes are the bytes of a JPEG encoded image, you can decode them, as they are, into a Bitmap :
ImageViewimageView= ...; //load image view defined in xml fileBitmapbitmap= BitmapFactory.decodeByteArray(packetBytes, 0 , packetBytes.length);
imageView.setImageBitmap(bitmap);
Post a Comment for "Get Byte Array Of Image From Inputstream Of Bluetooth"