本文整理汇总了C#中System.Windows.Media.Imaging.BitmapImage.GetAsFrozen方法的典型用法代码示例。如果您正苦于以下问题:C# BitmapImage.GetAsFrozen方法的具体用法?C# BitmapImage.GetAsFrozen怎么用?C# BitmapImage.GetAsFrozen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.BitmapImage
的用法示例。
在下文中一共展示了BitmapImage.GetAsFrozen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginSaveImage
public void BeginSaveImage(TileIndex id, BitmapImage image)
{
string imagePath = GetImagePath(id);
bool errorWhileDeleting = false;
bool containsOld = Contains(id);
if (containsOld && saveOption == SaveOption.ForceUpdate)
try
{
File.Delete(imagePath);
}
catch (IOException exc)
{
// todo возможно, тут добавить файл в очередь на удаление или перезапись новым содержимым
// когда он перестанет быть блокированным
Debug.WriteLine(String.Format("{0} - error while deleting tile {1}: {2}", Name, id, exc.Message));
errorWhileDeleting = true;
}
bool shouldSave = saveOption == SaveOption.ForceUpdate && !errorWhileDeleting ||
saveOption == SaveOption.PreserveOld && !containsOld;
if (shouldSave)
{
Debug.WriteLine("Began to save id = " + id);
Statistics.IntValues["ImagesSaved"]++;
ImageSaver saver = ScreenshotHelper.SaveBitmapToFile;
saver.BeginInvoke((BitmapImage)image.GetAsFrozen(), imagePath, null, null);
}
}
示例2: BeginLoadImageAsync
protected BitmapImage BeginLoadImageAsync(TileIndex id)
{
//Debug.Assert(Contains(id));
string imagePath = GetImagePath(id);
BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.UriSource = new Uri(imagePath);
try
{
bmp.EndInit();
}
catch (NotSupportedException exc)
{
Debug.WriteLine(String.Format("{0}: failed id = {1}. Exc = \"{2}\"", GetCustomName(), id, exc.Message));
Action corruptedFileDeleteAction = () =>
{
try
{
File.Delete(imagePath);
}
catch (Exception e)
{
Debug.WriteLine("Exception while deleting corrupted image file \"" + imagePath + "\": " + e.Message);
}
};
lock (fileDeleteActions)
{
fileDeleteActions.Add(corruptedFileDeleteAction);
if (!corruptedFilesDeleteTimer.IsEnabled)
corruptedFilesDeleteTimer.Start();
}
return null;
}
catch (FileNotFoundException exc)
{
Debug.WriteLine(String.Format("{0}: failed id = {1}. Exc = \"{2}\"", GetCustomName(), id, exc.Message));
return null;
}
return (BitmapImage)bmp.GetAsFrozen();
}