我想在圖像WPF(Syste.Windows.Controls.Image)中顯示圖像序列。 在圖像之間我想設置一個暫停作爲一個幀率。 在XAML我有c#代碼中的圖像序列圖像wpf
<Image x:Name="image" HorizontalAlignment="Left" Height="100" Margin="235,145,0,0" VerticalAlignment="Top" Width="100"/>
我想在一個週期內插入,但我爲什麼顯示ED停止(fps)的速度呢?
我已經tryed這一點,但不顯示圖像,如果不是最後的,我不喜歡線程暫停
for (int i = 2; i < 5; i++)
{
this.image.Source = new BitmapImage(new Uri("C:\\Users\\Pictures\\Braccio" + i + ".jpg", UriKind.Absolute));
System.Threading.Thread.Sleep(5000);
}
我不知道,如果你可以動畫'Image.Source',但您可以創建許多圖像和運行[關鍵幀動畫(http://msdn.microsoft.com/en-us/庫/ ms742524.aspx)來改變它們的可見性,從而產生想要的效果。你有沒有考慮過創建gif呢?一旦將其分配給「Image」,它將自動播放。 – Sinatr 2014-10-29 11:29:18
哦,你的錯誤顯然是在UI線程中一次完成整個工作。用戶界面不會在整個持續時間內更新,這就是爲什麼你只看到最後一幀*。您可以通過使用「DispatcherTimer」而不是「Thread.Sleep」來分割動畫。或者在單獨的'Task' /'Thread'中運行作業(使用'BackgroundWorker'),但是你需要在UI線程中調用*設置'Source'。 – Sinatr 2014-10-29 11:32:32
謝謝,但我需要在時間有一個圖像,因爲我比較此圖像與一個參考圖像。我曾經想過,我可以在一張圖片中顯示一張圖片,在2ms後用另一個ecc更改此圖片...因此,在同一時間,我將展示圖片與我的流式圖片進行比較。 – luca 2014-10-29 11:45:37