在形式和播放gif中显示大量的picturebox,使形式和gif冻结

发布于 2025-02-13 15:38:17 字数 1677 浏览 3 评论 0原文

我尝试以形式(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

探春 2025-02-20 15:38:17

而是使用“ begininvoke'而不是“调用”。 Invoke会使您的UI等到操作完成,这将使您的应用程序不响应或速度缓慢。在Windows应用程序中经常使用“ BeginInvoke”。

或者

我认为这是因为您的图片的大小与您的图片框不同,或者与图片框不同,因此它必须计算出来并需要时间。因此,如果您的picturebox具有const宽度和高度,请

  • 与图像相同的图像或gif大小,或者使用phitablebox进行调整大小
  • ,或者更改为正常,并且在Picturebox Sizemode上不进行任何更改

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

  • if your picturebox has const width and height, resize your image or gif with same size with picturebox
  • or change to normal and not do any change on picturebox sizemode
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文