我目前正在使用出色的 WriteableBitmapEx 框架为 Windows 应用商店 (WinRT) 编写一个小型图像编辑应用程序。由于像 .convolute 这样的功能在 WinRT 设备上可能需要一段时间(在 Surface 上测试)我想让这些请求异步,这样 UI 就不会被阻塞,我可以显示一个进度环。
这是我到目前为止所尝试的,代码本身正在运行。但是 UI 仍然被阻止并且环没有显示。该代码确实需要大约 2 秒才能执行。
// Start Image editing when selection is changed
private async void FilterListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
progressRing.IsActive = true;
try
{
filteredImage = await FilterMethod.imageBW(originalImage, filteredImage);
}
catch
{
Debug.WriteLine("No items selected");
}
mainImage.Source = filteredImage;
progressRing.IsActive = false;
}
// Black & White
public static async Task<WriteableBitmap> imageBW(WriteableBitmap originalImage, WriteableBitmap filteredImage)
{
filteredImage = originalImage.Clone();
using (filteredImage.GetBitmapContext())
{
filteredImage.ForEach(ImageEdit.toGrayscale);
}
return filteredImage;
}
// Grayscale
public static Color toGrayscale(int x, int y, Color color)
{
byte gray = (byte)(color.R * .3f + color.G * .59f + color.B * .11f);
Color newColor = Color.FromArgb(255, gray, gray, gray);
return newColor;
}