From 0f5bd697f9fede4658ca2b4055369a72725fbd4e Mon Sep 17 00:00:00 2001 From: "Richard Z.H. Wang" Date: Sat, 12 Oct 2013 12:33:34 +1100 Subject: [PATCH] LoadFromResource depend on Load method on WinRT So it can load to a WriteableBitmap instead of BitmapImage, and use the fallback loader if needed --- Splat/WinRT/Bitmaps.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Splat/WinRT/Bitmaps.cs b/Splat/WinRT/Bitmaps.cs index 95d65aa05..210a6f887 100644 --- a/Splat/WinRT/Bitmaps.cs +++ b/Splat/WinRT/Bitmaps.cs @@ -56,21 +56,12 @@ public async Task Load(Stream sourceStream, float? desiredWidth, float? } } - public Task LoadFromResource(string resource, float? desiredWidth, float? desiredHeight) + public async Task LoadFromResource(string resource, float? desiredWidth, float? desiredHeight) { - // NB: I'm sure there's a way to return a constant as a Task but - // I'm too lazy to look it up. - return Task.Run(() => { - var source = new BitmapImage(); - - if (desiredWidth != null) { - source.DecodePixelWidth = (int)desiredWidth; - source.DecodePixelHeight = (int)desiredHeight; - } - - source.UriSource = new Uri(resource); - return (IBitmap)new BitmapImageBitmap(source); - }); + var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(resource)); + using (var stream = await file.OpenAsync(FileAccessMode.Read)) { + return await Load(stream.AsStreamForRead(), desiredWidth, desiredHeight); + } } public IBitmap Create(float width, float height)