StreamSocket to Stream in windows phone 8
- by Abouzar Nouri
I am trying to use Bluetooth in WP8 to send an image from my app on a device and show it in my app on another device. The receiver has a StreamSocket object to read the data from it like the code below
await _dataReader.LoadAsync(4);
uint messageLen = (uint)_dataReader.ReadInt32();
await _dataReader.LoadAsync(messageLen);
string imageData _dataReader.ReadString(messageLen);
Then I have to save all the received data (image) on the device and then create a Stream object from the stored data to give it to the BitmapSource.SetSource(Stream) function to be able to show this image on my app.
var image = new BitmapImage();
image.SetSource(stream);
All I want to do is not to skip this double work and directly convert the StreamSocket object (from Bluetooth connection) to a Stream object and make the BitmapSource image. Is there any way to do this?