本文整理匯總了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();
}