2

Nokia just released 'Nokia Imaging SDK' version 1. However, now I can not use a Stream download image since SDK's StreamImageSource tries to use Stream.Length which is unavailable for Async Stream. How can I get around this issue?

Here is my code:

HttpClient c = new HttpClient();
Stream orgImageStream = await c.GetStreamAsync(imageUri);
var imageSource = new StreamImageSource(orgImageStream);  //fails here since he tries to use Stream.Length
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
João Louros
  • 2,752
  • 4
  • 23
  • 30

1 Answers1

3

Interesting bug - it would be useful to report it to Nokia.
Anyway, you can solve it by either saving the file to isolated storage first, or copying it to MemoryStream locally:

HttpClient c = new HttpClient();
Stream orgImageStream = await c.GetStreamAsync(imageUri);

MemoryStream ms = new MemoryStream();
await orgImageStream.CopyToAsync(ms);
ms.Seek(0, SeekOrigin.Begin);
var imageSource = new StreamImageSource(ms);

But don't forget to use all Streams in using (Stream ... ) { ... } to Dispose them properly!

Martin Suchan
  • 10,600
  • 3
  • 36
  • 66
  • After some late night coding I figured out a similar approach. I cast the Stream to a byte[] and pass it to a MemoryStream to feed StreamImageSource. I haven't tried your approach, but I will mark it as answered. Thanks Martin – João Louros Nov 14 '13 at 14:39
  • 3
    Note that since the stream data is now in fact loaded in memory, you can avoid some overhead by using BufferImageSource instead. – CÅdahl Nov 18 '13 at 08:51