Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从png图像平滑动画(视频)_C#_Wpf_Bitmapimage - Fatal编程技术网

C# 从png图像平滑动画(视频)

C# 从png图像平滑动画(视频),c#,wpf,bitmapimage,C#,Wpf,Bitmapimage,我不能用我的图像制作视频文件,因为我需要保持png文件的透明度 <!-- Animate the TranslateTransform's X property from 0 to 350, then 50, then 200 over 10 seconds. --> <DoubleAnimationUsingKeyFrames Storyboard.T

我不能用我的图像制作视频文件,因为我需要保持png文件的透明度

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
我想要每秒25帧,不要延迟

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
1000多个图像1920x1080,从8 KB到5 MB

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
我怎样才能做到这一点

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
以下是我尝试过的例子:

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
1例: 由于上传图像,图片被禁止

int counter = 0;
DispatcherTimer dT = new DispatcherTimer();

public Png()
{
   InitializeComponent();

   dT.Interval = new TimeSpan(0, 0, 0, 0, 40);
   dT.Tick += new EventHandler(dT_Tick);
   dT.Start();
}

void dT_Tick(object sender, EventArgs e)
{
   var image = new BitmapImage(new Uri("C:\\" + counter + ".png"));
   imageBox.Source = image;
   counter++;

   if (counter == 1000)
   {
     dT.Stop();
   }
}
          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
2例: 由于文件太多,RAM非常阻塞。而且,也感觉到了阻力

    int counter = 0;
    DispatcherTimer dT = new DispatcherTimer();
    private BitmapImage[] images;

    public Png()
    {
       InitializeComponent();

       images = new BitmapImage[1000];

       for(int i = 0 ; i < images.Length; i++)
       {
          images[i] = new BitmapImage(new Uri("C:\\" + i + ".png"));
       }

       dT.Interval = new TimeSpan(0, 0, 0, 0, 40);
       dT.Tick += new EventHandler(dT_Tick);
       dT.Start();
    }



   void dT_Tick(object sender, EventArgs e)
   {
      imageBox.Source = images[counter];
      counter++;

      if (counter == 1000)
      {
        dT.Stop();
      }
   } 
          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
3例如:

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
我试着排队

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
队列试图用作图片缓冲区。 首先,我上传了10张图片到队列中。 显示第一张图片。 当我显示第二张图片时,我删除了第一张图片,并将另一个线程中的第十一张图片添加到队列中

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>

但我得到的印象是,我做错了,也感觉到刹车,多次更正代码,最终意外删除。

我将把修改发布到示例2,因为我认为它更有效,我还鼓励您使用示例1进行试验

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
在表单中再添加一个图像框,并确保两个图像框的位置和大小相同

void dT_Tick(object sender, EventArgs e)
{
      if (counter % 2 != 0) {
         imageBox1.Source = images[counter];
         imageBox1.Visible = true;
         imageBox2.Visible = false;
      }
      else {
         imageBox2.Source = images[counter];
         imageBox2.Visible = true;
         imageBox1.Visible = false;
      }
      counter++;

      if (counter == 1000)
      {
        dT.Stop();
      }
} 
          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>

我将把修改后的内容发布到示例2中,因为我认为它更有效,我还鼓励您使用示例1进行实验

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
在表单中再添加一个图像框,并确保两个图像框的位置和大小相同

void dT_Tick(object sender, EventArgs e)
{
      if (counter % 2 != 0) {
         imageBox1.Source = images[counter];
         imageBox1.Visible = true;
         imageBox2.Visible = false;
      }
      else {
         imageBox2.Source = images[counter];
         imageBox2.Visible = true;
         imageBox1.Visible = false;
      }
      counter++;

      if (counter == 1000)
      {
        dT.Stop();
      }
} 
          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>

//对于帧速率,将其添加到XAML中

<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0.5" 
                 From="1.0" To="0.5" Timeline.DesiredFrameRate="25" />
          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
关键帧动画在WPF中是可能的。通过为每个图像插入关键帧,在情节提要中添加所有图像。关键帧在时间轴中看起来像菱形。您可以手动将它们添加到对象和时间轴中

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
//平滑动画

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>

//对于帧速率,将其添加到XAML中

<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0.5" 
                 From="1.0" To="0.5" Timeline.DesiredFrameRate="25" />
          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
关键帧动画在WPF中是可能的。通过为每个图像插入关键帧,在情节提要中添加所有图像。关键帧在时间轴中看起来像菱形。您可以手动将它们添加到对象和时间轴中

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>
//平滑动画

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>

          <!-- Animate the TranslateTransform's X property
               from 0 to 350, then 50,
               then 200 over 10 seconds. -->

          <DoubleAnimationUsingKeyFrames
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X"
            Duration="0:0:10">
            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            <LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
          </DoubleAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Rectangle.Triggers> 
</Rectangle>

是否使用混合关键帧?是否尝试创建GIF?你可以把它当作一个image@Tofik我不能使它的GIF的原始重量的所有PNG 5+GB-我需要一个逐帧的动画PNG@Tofik我试着在一个单独的线程中进行缓冲,我写了例3,但我不小心删除了它,有一个雕带,牙齿闻起来像是xy问题,你想要一个视频,但是你不想要视频,你是在使用混合关键帧吗?你尝试过创建GIF吗?你可以把它当作一个image@Tofik我不能使它的GIF的原始重量的所有PNG 5+GB-我需要一个逐帧的动画PNG@Tofik我试着在一个单独的线程中进行缓冲,我写了例3,但我不小心删除了它,有一个雕带,牙齿闻起来像是xy问题,你想要一个视频,但你们不想要一个视频,它不会改变任何东西。你们有并没有试着把控件的DoubleBuffer属性改为true?我想你们误解了我的需要。它并没有改变任何东西。您是否尝试将控件的DoubleBuffer属性更改为true?我想您误解了我的需要。