大家好,
我已提取视频的总框架和保存在输出目录。现在,我已经随着帧没有显示在WPF窗口的ListBox中的所有farmes。在每一帧。
int FramesCount = 0;
List<stackpanel> splist = new List<stackpanel>();
System.IO.DirectoryInfo myimagesdir = new System.IO.DirectoryInfo(@"E:\\tmp");
foreach(System.IO.FileInfo myimagesfile in myimagesdir.GetFiles("*.jpg"))
{
FramesCount = FramesCount + 1;
StackPanel sp = new StackPanel();
sp.Height = 100; sp.Width = 125;
Image img = new Image();
img.Height = 80; img.Width = 100;
BitmapImage bitimg = new BitmapImage();
bitimg.BeginInit();
bitimg.UriSource = new Uri(myimagesfile.FullName);
bitimg.CacheOption = BitmapCacheOption.OnLoad;
bitimg.EndInit();
img.Source = bitimg;
TextBlock tb = new TextBlock();
tb.Height = 20; tb.Width = 30; tb.FontSize = 15;
tb.Text = FramesCount.ToString();
sp.Children.Add(tb);
sp.Children.Add(img);
splist.Add(sp);
}
Frameslistbox.ItemsSource = splist;
在这里,我为每个文件创建一个StackPanel,图像和TextBlock。
图像和TextBlock添加到StackPanel中的儿童,并这stackpanels被添加到列表。
现在这里每一次创建新对象。我如何处置旧的对象,在foreach循环?
谢谢