Skip to content

Commit

Permalink
Merge pull request #22 from paulcbetts/winrt-resload-to-writeablebitmap
Browse files Browse the repository at this point in the history
Bitmap LoadFromResource depend on Load method on WinRT
  • Loading branch information
Paul Betts committed Oct 12, 2013
2 parents c57020d + 0f5bd69 commit 5819802
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions Splat/WinRT/Bitmaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,12 @@ public async Task<IBitmap> Load(Stream sourceStream, float? desiredWidth, float?
}
}

public Task<IBitmap> LoadFromResource(string resource, float? desiredWidth, float? desiredHeight)
public async Task<IBitmap> 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)
Expand Down

0 comments on commit 5819802

Please sign in to comment.