João Louros
João Louros

Reputation: 2760

Unable to use downloaded image using the Nokia imaging SDK

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

Upvotes: 2

Views: 258

Answers (1)

Martin Suchan
Martin Suchan

Reputation: 10620

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!

Upvotes: 3

Related Questions