在形式和播放gif中显示大量的picturebox,使形式和gif冻结
我尝试以形式(30-40个图片框,每个.gif映像为200-500kb)编写一个带有大量GIF动画的应用程序。但是,当我使用太多的picturebox并运行程序时,表单会冻结过多,而通常需要以100ms以100ms传递到下一个图像的GIF动画,请在5-6秒内移至下一个图像。如何处理这种情况。谢谢,
我试图在GIF中展示图片,但我也有相同的结果
public class Class1 : PictureBox
{
public Class1()
{
}
public Image[] imagelist { get; set; } = new Image[10];
public int currentimage;
private int imagecount = 1;
protected override void OnCreateControl()
{
base.OnCreateControl();
this.Image = imagelist[0];
imagecount = imagelist.TakeWhile(r => r != null).Count();
}
public void NextImage()
{
currentimage = (currentimage + 1) % imagecount;
this.Image = imagelist[currentimage];
}
}
public Form1()
{
InitializeComponent();
array = this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
.Where(f => f.GetValue(this) != null&&f.FieldType == typeof(Class1)).Select(f => f.GetValue(this)).Cast<Class1>().ToArray();
Thread = new Thread(Start);
Thread.Start();
}
private Thread Thread;
private void Start()
{
Thread.Sleep(400);
while (true)
{
this.Invoke((MethodInvoker)(() =>
{
foreach (Class1 class1 in array)
{
class1.NextImage();
}
}));
Thread.Sleep(100);
}
}
I try to write an application with a large number of GIF animations in a form (30-40 picture boxes and each .gif image is 200-500kb). However, when I use so much Picturebox and run the program, the form freezes too much, and the gif animations that normally need to pass to the next image in 100MS, move to the next image within 5-6 seconds. How to handle this situation. Thank you
I tried to show pictures ,in gif, one by one that way but i had same result
public class Class1 : PictureBox
{
public Class1()
{
}
public Image[] imagelist { get; set; } = new Image[10];
public int currentimage;
private int imagecount = 1;
protected override void OnCreateControl()
{
base.OnCreateControl();
this.Image = imagelist[0];
imagecount = imagelist.TakeWhile(r => r != null).Count();
}
public void NextImage()
{
currentimage = (currentimage + 1) % imagecount;
this.Image = imagelist[currentimage];
}
}
public Form1()
{
InitializeComponent();
array = this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
.Where(f => f.GetValue(this) != null&&f.FieldType == typeof(Class1)).Select(f => f.GetValue(this)).Cast<Class1>().ToArray();
Thread = new Thread(Start);
Thread.Start();
}
private Thread Thread;
private void Start()
{
Thread.Sleep(400);
while (true)
{
this.Invoke((MethodInvoker)(() =>
{
foreach (Class1 class1 in array)
{
class1.NextImage();
}
}));
Thread.Sleep(100);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而是使用“ begininvoke'而不是“调用”。 Invoke会使您的UI等到操作完成,这将使您的应用程序不响应或速度缓慢。在Windows应用程序中经常使用“ BeginInvoke”。
或者
我认为这是因为您的图片的大小与您的图片框不同,或者与图片框不同,因此它必须计算出来并需要时间。因此,如果您的picturebox具有const宽度和高度,请
Use 'BeginInvoke' instead 'Invoke'. Invoke makes your ui wait until action finished and it will make your app not responding or slow. Use 'BeginInvoke' often in windows apps.
or
I think it's because your pictures has different size than your picturebox or has different w/h ratio from picturebox so it had to calculate the streching and takes time. So you can do