Created
May 19, 2014 20:22
-
-
Save ceee/ec46d5bde94d7a72c189 to your computer and use it in GitHub Desktop.
This file contains 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
public static Uri SaveTile(UserControl control, string filename, double width, double height) | |
{ | |
string path = tileFolder + filename + ".png"; | |
bool success = true; | |
Deployment.Current.Dispatcher.BeginInvoke(() => | |
{ | |
control.Width = width; | |
control.Height = height; | |
control.Measure(new Size(width, height)); | |
control.Arrange(new Rect(0, 0, width, height)); | |
try | |
{ | |
ExtendedImage tileImaged = control.ToImage(); | |
if (tileImaged == null || tileImaged.PixelWidth < 100) | |
{ | |
success = false; | |
} | |
else | |
{ | |
Encoders.AddEncoder<PngEncoder>(); | |
PngEncoder pngEncoder = new PngEncoder(); | |
using (var isf = IsolatedStorageFile.GetUserStoreForApplication()) | |
{ | |
using (var stream = isf.OpenFile(path, System.IO.FileMode.OpenOrCreate)) | |
{ | |
pngEncoder.Encode(tileImaged, stream); | |
stream.Close(); | |
success = true; | |
} | |
} | |
} | |
} | |
catch | |
{ | |
success = false; | |
} | |
}); | |
if (success == false) | |
{ | |
throw new PokiException("Tile could not be saved"); | |
} | |
return new Uri("isostore:" + path, UriKind.Absolute); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment