【发布时间】:2014-10-28 19:17:50
【问题描述】:
我想通过蓝牙从硬件接收 android 中的 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 图像数据: 主.cpp http://pastebin.com/Tx8YkbYF JPEGCamera.cpp http://pastebin.com/0jHQ8WvT
【问题讨论】:
-
你检查Byte Array to Image File了吗?
-
是的检查但没有结果@Daniel
-
你会帮忙吗? @丹尼尔
-
“显示 jpg 图像”到底是什么意思?您希望在哪里显示此图片?
-
我想将图像显示到图像视图中。我尝试了超过 4 天。但我失败了。 @丹尼尔