Java 使用Android BluetoothSpp库发送位图
我正在使用。我有发送和接收数据字节[]的问题 用户1从照相机中拍摄照片,获取照片并发送给其他用户Java 使用Android BluetoothSpp库发送位图,java,android,bitmap,bluetooth,android-bitmap,Java,Android,Bitmap,Bluetooth,Android Bitmap,我正在使用。我有发送和接收数据字节[]的问题 用户1从照相机中拍摄照片,获取照片并发送给其他用户 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 0) { if (resultCode == RESULT_OK) { Bundle bundle =
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
Bitmap bitmap = (Bitmap) bundle.get("data");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
byte[] bitmapByte = outputStream.toByteArray();
bluetoothSPP.send(bitmapByte, true); **//Send the Bitmap array**
}
}
用户2接收位图字节[]
bluetoothspp.setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() {
public void onDataReceived(byte[] data, String message) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
Glide.with(ChatActivity.this).load(bitmap ).asBitmap().into(imgFundo); //Use Glide for show Bitmap
}
});
但我总是会出错,Glide无法显示图像。
我进行了调试,数据分为几个部分,比如字节数组。
-如何根据接收到的数据构建位图
谢谢你说我不能做是什么意思?怎么了?@OlcayErtaş我收到一个字节数组。数据分为多个部分。