About WriteableBitmapEx

Oct 5, 2012 at 4:48 PM
Edited Oct 5, 2012 at 4:49 PM


1) When I run the following instruction, I got the " Value does not fall within the expected range" exception. ImagePath is aslo contained correct uri.

WriteableBitmap wbTemp = await wbResize.FromContent(new Uri(ImageUriPath, UriKind.Absolute));

2) byte[] btarrImage = await httpClient.GetByteArrayAsync(ImageUriPath);wbResize = wbResize.FromByteArray(btarrImage);
await wbResize.SaveToFile(ApplicationData.Current.LocalFolder, "Test.jpg");

After running above 3 lines, image can't save correctly.


Oct 5, 2012 at 5:21 PM

You can't just pass an uri to the FromContent method. It's only for local images, not remote.

Use the FromStream method with the httpClient.GetStream method as input.


- rene schulte

Oct 8, 2012 at 4:25 AM


Thanks for your quick reply.

When I use httpClient.GetStreamAsync(uristring), it return Stream.

FromStream method  allow only IRandomAccessStream.

Thus type mismatch compiler errors occurred.

How can I do? Please help me.


Oct 8, 2012 at 11:14 AM

I just checked in another overload for the FromStream method which takes a .NET stream directly:

      public static async Task<WriteableBitmap> FromStream(this WriteableBitmap bmp, Stream stream)
         using (var dstStream = new InMemoryRandomAccessStream())
            await RandomAccessStream.CopyAsync(stream.AsInputStream(), dstStream);
            return await FromStream(bmp, dstStream);

Get the latest source code from the respository or use this method above.


- Rene

Oct 8, 2012 at 11:21 AM

Thanks you very much, I will try with this way.