Created
May 19, 2014 20:29
-
-
Save ScottIsAFool/e474b8150dd9732ee348 to your computer and use it in GitHub Desktop.
Save UserControl for tile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task ToImage(UIElement element, string filename, double height, double width) | |
{ | |
element.UpdateLayout(); | |
element.Measure(new Size(width, height)); | |
element.UpdateLayout(); | |
element.Arrange(new Rect { Height = height, Width = width }); | |
var bitmap = new WriteableBitmap((int)width, (int)height); | |
bitmap.Render(element, null); | |
bitmap.Invalidate(); | |
await SaveTheImage(bitmap, filename); | |
GC.Collect(); | |
} | |
private async Task SaveTheImage(WriteableBitmap bitmap, string filename) | |
{ | |
using (var fileStream = await StorageService.CreateFileAsync(filename)) | |
{ | |
bitmap.SavePng(fileStream); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment