本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.WritePng方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.WritePng方法的具体用法?C# WriteableBitmap.WritePng怎么用?C# WriteableBitmap.WritePng使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.WritePng方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveElement
public static bool SaveElement(UIElement element, Tile tile)
{
try
{
var side = (tile == Tile.Small) ? 159 : 336;
element.Measure(new Size(side, side));
element.Arrange(new Rect(0, 0, side, side));
var bmp = new WriteableBitmap(side, side);
bmp.Render(element, null);
bmp.Invalidate();
var name = tile.ToString() + Guid.NewGuid() + ".png";
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isf.DirectoryExists("/CustomLiveTiles"))
{
isf.CreateDirectory("/CustomLiveTiles");
}
using (var myFileStream = isf.CreateFile("shared/shellcontent/" + name))
{
// Encode WriteableBitmap object to a PNG stream.
bmp.WritePng(myFileStream);
}
var filesTodelete =
from f in isf.GetFileNames("shared/shellcontent/" + tile + "*").AsQueryable()
where !f.EndsWith(name)
select f;
foreach (var file in filesTodelete)
{
isf.DeleteFile("shared/shellcontent/" + file);
}
}
SaveTilePart("isostore:/Shared/ShellContent/" + name, tile);
}
catch (Exception)
{
Thread.Sleep(1000);
if (tile == Tile.Small)
{
SaveTilePart(GetDefaultSmallTile(), tile);
}
else
{
SaveTilePart((tile == Tile.Front) ? GetDefaultFrontTile() : GetDefaultBackTile(), tile);
}
return false;
}
return true;
}