播放gif图像序列 [英] play sequence of gif image

查看:120
本文介绍了播放gif图像序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,我正在努力播放gif图像的序列,但它总是只显示我的最后一张图像,我试着写一个等待2秒后再从db获取下一张图像的计时器,但它没有工作,请你帮帮我吧。

  for  int  i =  0 ; i <  = myList.Count  -   1 ; i ++)
{
data = myList [i] .ToString();
// Console.WriteLine(data);
data = what_word(data );
if (!data.Equals( 找不到))
{

command.CommandText = SELECT picturename FROM pictures WHERE word =' + data + ';;

command.Parameters.AddWithValue( @ word,myList [i ]的ToString());

reader1 = command.ExecuteReader();


while (reader1.Read())
{

// Console.WriteLine(reader1 [0] .ToString());
string imagename = D:\\\\\\\\\\\\\\\\\ C#\\db1\\;
imagename = imagename + reader1 [ 0 ]。ToString();
// Console.WriteLine(imagename);
tt1 = Image.FromFile (imagename);

pictureBox1.Image = tt1;


}

}

reader1.Close();

}

解决方案

好的,好的......这可能很有趣......



问题很简单,但可能需要一点解释。



让我们简化你的代码...... 。

  int  myInt =  0 ; 
for int i = 0 ; i < 5 ; i ++)
{
myInt = i ;
}

您希望该代码能做什么?它将如何区别于:

  int  myInt =  5   -   1 ; 

您的代码执行相同的操作。它从数据库中读取一组图像名称,然后将它们转换为图像,并将它们一个接一个地分配给图片框。就像 int 一样,图片框最后只有最终值,好像你的循环不存在一样。



因此,将代码更改为:

设置类级别的字符串列表,并在进入循环之前将其清除。

设置类级整数索引它。

在循环中,不是创建图像,而是将名称添加到List。

循环后,将索引设置为零。

现在,在表单中添加一个Timer,它有一个适合切换图像的Interval。

在Tick事件处理程序中,检查索引 - 如果它大于或等于List.Count什么都不做。

否则,获取List项和索引,并在下次增加索引。

现在获取Image,并设置PictureBox。图像属性。


good morning , i''m working on playing sequence of gif image ,but it always show me the last image only , i tried to write a timer that will wait 2 second before getting next image from db , but it doesn''t work, could you help me please .

for (int i = 0; i <= myList.Count - 1; i++)
           {
               data = myList[i].ToString();
               // Console.WriteLine(data);
               data = what_word(data);
               if (!data.Equals("not found"))
               {

                   command.CommandText = "SELECT picturename FROM pictures WHERE word = '" + data + "';";

                   command.Parameters.AddWithValue("@word", myList[i].ToString());

                   reader1 = command.ExecuteReader();


                   while (reader1.Read())
                   {

                     // Console.WriteLine(reader1[0].ToString());
                       string imagename = "D:\\grad.projec\\C#\\db1\\";
                       imagename = imagename + reader1[0].ToString();
                       //Console.WriteLine(imagename);
                     tt1 = Image.FromFile(imagename);
                   
                      pictureBox1.Image = tt1;


                   }

               }
               
               reader1.Close();

           }

解决方案

Ok, ok...this may be fun...

The problem is quite simple, but it may take a little explaining.

Lets simplify your code a bit...

int myInt = 0;
for (int i = 0; i < 5; i++)
   {
   myInt = i;
   }

What would you expect that code to do? And how would it differ from:

int myInt = 5 - 1;

Your code does the same thing. It reads a collection of image names from teh DB, then it converts them to Images, and assigns them one after the other to your picture box. Just like with an int, the picture box ends up with just the final value, as if your loop did not exist.

So, change your code to:
Set up a class level List of strings, and clear it before you enter your loop.
Set a class level integer to index it.
In the loop, instead of creating an image, add the name to the List.
After the loop, set the index to zero.
Now, add a Timer to your form, which has an Interval suitable for switching images.
In the Tick event handler, check the index - if it is greater than or equal to the List.Count do nothing.
Otherwise, get the List item and the index, and increment the index for next time.
Now get the Image, and set the PictureBox.Image property.


这篇关于播放gif图像序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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