我正在开发处理图像的应用程序。图像处理需要一些时间(大约 10 秒)。我想添加一个进度条来完成,除非图像处理完成。我在 xaml 中有这个进度条
<ProgressBar Width="200"
Foreground="#FF8B64C3"
Value="20"
Maximum="100"
BorderBrush="#FF411F72"
BorderThickness="1"/>
这是点击按钮进行图像处理时调用的事件
private void ProcessImageButton_Click(object sender, RoutedEventArgs e)
{
applyFilters(image1Pixels, image1Width, image1Height);
}
我想在单击此 ProcessImageButton 按钮时启动进度条。这是 applyFilters 方法。
private async void applyFilters(byte[] pixels, uint width, uint height)
{
ProcessImage processImage = new ProcessImage(pixels, width, height);
byte[] effect = processImage.applyEffect(width, height);
WriteableBitmap result_image = new WriteableBitmap((int)width, (int)height);
using (Stream stream = result_image .PixelBuffer.AsStream())
{
await stream.WriteAsync(effect, 0, effect.Length);
MainImage.Source = result_image ;
}
}
我希望我的进度条在将 result_image 存储到 MainImage.Source 之前完成。
最佳答案
你可以使用不确定的进度条
<ProgressBar x:Name="ImageProgressBar" Visibility="Collapsed" IsIndeterminate="true"/>
并且你需要在图片加载前后改变可见性
ImageProgressBar.Visibility = Visibility.Visible;
ImageProgressBar.Visibility = Visibility.Collapsed;
关于c# - 异步方法 C# 中的 UWP 进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37866452/