【发布时间】:2016-06-16 18:09:19
【问题描述】:
我正在开发处理图像的应用程序。图像处理需要一些时间(大约 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 之前完成我的进度条。
【问题讨论】:
-
你有什么问题?到目前为止,您尝试了什么?
-
你需要显示你的工作进度还是你想要一个不确定的进度条?
-
@Romasz 我想要在图像上应用过滤器过程中的进度条。
-
那么我认为您应该能够将您的工作(例如写作)分成更小的块,可能通过缓冲区并使用 Progress 类来报告 UI 的更改(@987654321 @,你一定会找到更多)。我也可能会考虑将您的工作重定向到单独的线程。
-
如果您不知道操作将花费的时间,您应该使用进度环,而不是进度条!