我想通過藍牙從硬件接收安卓的jpeg圖像。 我想讀取輸入流並顯示來自字節數組的實際數據。 我的實際數據是這樣的:獲取來自藍牙輸入流的圖像的字節數組
ff d8 ff e1 63 70 45 78 69 66 00 00 49 49 2a 00
08 00 00 00 0b 00 0f 01 02 00 06 00 00 00 92 00
.........................ff d9
我用這個代碼:
void openBT() throws IOException
{
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standard SerialPortService ID
mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
mmSocket.connect();
mmOutputStream = mmSocket.getOutputStream();
mmInputStream = mmSocket.getInputStream();
beginListenForData();
//ConnectedThread(mmSocket);
myLabel.setText("Bluetooth Opened");
}
void beginListenForData()
{
final Handler handler = new Handler();
final byte delimiter = 10; //This is the ASCII code for a newline character
stopWorker = false;
readBufferPosition = 0;
readBuffer = new byte[1024];
workerThread = new Thread(new Runnable()
{
public void run()
{
while(!Thread.currentThread().isInterrupted() && !stopWorker)
{
try
{
int bytesAvailable = mmInputStream.available();
if(bytesAvailable > 0)
{
final byte[] packetBytes = new byte[bytesAvailable];
mmInputStream.read(packetBytes);
StringBuilder sb = new StringBuilder();
for (byte b : packetBytes) {
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","data"+sb.toString());
handler.post(new Runnable()
{
public void run()
{
//ByteArrayInputStream imageStream = new ByteArrayInputStream(packetBytes);
// Bitmap bitmap = BitmapFactory.decodeStream(imageStream);
// image.setImageBitmap(bitmap);
}
});
}
}
catch (IOException ex)
{
stopWorker = true;
}
}
}
});
workerThread.start();
}
什麼我得到的是:
6163206339203564203264203138203...........
463206620666620643920
如何顯示實際結果(十六進制值)在logcat中,然後從十六進制值顯示JPG圖像?
我用下面的代碼從相機發送JPG圖像數據: 的main.cpp http://pastebin.com/Tx8YkbYF JPEGCamera.cpp http://pastebin.com/0jHQ8WvT
你檢查[字節數組圖像文件](http://stackoverflow.com/questions/1580038/byte-array-to-image-file)? – Daniel 2014-09-04 06:42:50
是的檢查,但沒有結果@Daniel – DarkenShooter 2014-09-04 07:33:24
你會幫忙嗎? @Daniel – DarkenShooter 2014-09-04 07:37:50