2010-01-20 75 views

回答

1

我一直在使用RenderTargetBitmap對象來呈現這樣的動畫圖像序列:

首先你撥打:

myStoryboard.CurrentTimeInvalidated += new EventHandler(onCurrentTimeInvalidated); 

其中myStoryboard是故事板驅動的動畫,然後你有以下方法:

void onCurrentTimeInvalidated (object sender, EventArgs e) 
     { 
      prefix = ""; 
      if (counter < 10) 
      { 
       prefix = "000"; 
      } 
      else if (counter < 100) 
      { 
       prefix = "00"; 
      } 
      else if (counter < 1000) 
      { 
       prefix = "0"; 
      } 

      Size size = new Size(MainCanvas.ActualWidth, MainCanvas.ActualHeight); 
      MainCanvas.Measure(size); 
      MainCanvas.Arrange(new Rect(size)); 


      RenderTargetBitmap bmp = new RenderTargetBitmap(imgWidth, imgHeight, 96d, 96d, PixelFormats.Default); 
      bmp.Render(MainCanvas); 

      JpegBitmapEncoder encoder = new JpegBitmapEncoder(); 
      encoder.QualityLevel = 90; 
      encoder.Frames.Add(BitmapFrame.Create(bmp)); 
      string file = basePath + prefix + counter.ToString() + "_testpic.jpg"; 
      using (Stream stm = File.Create(file)) 
      { 
       encoder.Save(stm); 
      } 
      counter++; 
     } 

我不確定這將如何與MediaElement一起工作,但它可能值得一試。儘管您需要從MediaTimeline中驅動MediaElement,並從它的CurrentTimeInvalidated事件中調用onCurrentTimeInvalidated方法,但爲此可以在MediaElement上工作。