如何将一系列图像自动加载到Windows窗体的图片框中? [英] How to load a sequence of images automatically into a picture box in windows forms?

查看:111
本文介绍了如何将一系列图像自动加载到Windows窗体的图片框中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列图像,希望以自动化方式(例如幻灯片播放)在图片框中显示
我尝试使用计时器

 私有  void  timer1_Tick(对象发​​件人,EventArgs e)
        {
            如果(我<   15 )
            {
                pictureBox1.ImageLocation = "  + i +  .jpg";
                i ++;
            }
        } 


但是它会完成整个序列并仅显示最后一张图像.
我什至尝试使用线程

 abc:
            如果(我<   15 )
            {
                pictureBox1.ImageLocation = "  + i +  .jpg";
                i ++;
                Thread.Sleep( 200 );
                转到 abc;
            } 


但是它仅显示最后一张图像.
有人可以帮我吗?

解决方案

是因为当我到15岁时,这就是球类比赛.相反:

 如果(i <   15 )
{
    pictureBox1.ImageLocation = "  + i +  .jpg";
    i ++;
    如果(i ==  15 )
        i =  1 ;
} 



或者您可以将其更改为:

 私有  void  timer1_Tick(对象发​​件人,EventArgs e)
{
    pictureBox1.ImageLocation = "  + i +  .jpg";
    i ++;
    如果(i ==  15 )
        i =  1 ;
} 


请不要按"answer"来添加评论,也不要编辑您的帖子.如果您有答案",请按一下答案.

回答你的人是正确的.而且,这确实非常简单且合乎逻辑.您知道如何使用调试器吗?很明显,您不习惯思考代码的功能.使用调试器在代码中查找特定的问题.线程与线程无关(尽管您没有使用线程,但是只是使线程暂停,并在疯狂的地方使用了goto).

您应该阅读一本基础书籍,以全面掌握编程知识,但是要解决此问题,只需使用调试器,然后在需要显示代码并特别告诉我们您仍然感到困惑的地方编辑帖子.

它仍然不起作用.如果我尝试在达到15时将其重置为1,则整个编会进入某种无限循环,并且根本不会显示任何图片...实际上,该窗体永远不会打开.

如果我尝试在计时器中将其重置,则图片框将永远不会显示.


I have a sequence of images which i want to display in a picture box in an automated way (i.e something like a slideshow)
I tried using a timer

private void timer1_Tick(object sender, EventArgs e)
        {
            if (i < 15)
            {
                pictureBox1.ImageLocation = "C:\\vlcsnaps\\" + i + ".jpg";
                i++;
            }
        }


But it completes the entire sequence and displays only the last image.
I even tried using a thread

abc:
            if (i < 15)
            {
                pictureBox1.ImageLocation = "C:\\vlcsnaps\\" + i + ".jpg";
                i++;
                Thread.Sleep(200);
                goto abc;
            }


But it displays only the last image.
Can someone help me out?

解决方案

it''s because when i gets to 15, that''s the ball game. Instead:

if (i < 15)
{
    pictureBox1.ImageLocation = "C:\\vlcsnaps\\" + i + ".jpg";
    i++;
    if (i == 15)
        i = 1;
}



Or you could change it to:

private void timer1_Tick(object sender, EventArgs e)
{
    pictureBox1.ImageLocation = "C:\vlcsnaps\\" + i + ".jpg";
    i++;
    if (i==15)
        i = 1;
}


Please don''t push ''answer'' to add comments, edit your post. Push answer if you have an ''answer''.

The person who answered you is correct. And, it''s really pretty simple and logical. Do you know how to use the debugger ? It''s plain you''re not used to thinking about what your code does. Use the debugger to find the specific issue in your code. Threads have nothing to do with it ( although you did not use a thread, you just made your thread pause, and used a goto in an insane place ).

You should read a basic book to get the hang of programming in general, but for fixing this issue, just use the debugger, and edit your post if you need to show us code and tell us specifically where you are still confused.


It still doesn''t work. If i try resetting i back to 1 when it reaches 15, the entire prog goes into some kind of infinite loop and never displays any picture at all......in fact the form never opens.

If i try resetting this in the timer, then the picture box never gets displayed.


这篇关于如何将一系列图像自动加载到Windows窗体的图片框中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆