2017-06-13 20 views

回答

0

有沒有試過? 如何:

添加引用:

PresentationCore.dll 
System.Xaml.dll 
WindowsBase.dll 

添加變量到您的窗體:

List<Bitmap> bitmapList = new List<Bitmap>(); 

調用此梅託德保存面板的狀態(GIF幀)

private void SavePanel() 
{ 
    Bitmap bmp = new Bitmap(panel1.Width, panel1.Height); 
    panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height)); 
    bitmapList.Add(bmp); 
} 

調用此方法從保存的幀創建Gif:

private void SaveGif() 
{ 
    System.Windows.Media.Imaging.GifBitmapEncoder gEnc = new System.Windows.Media.Imaging.GifBitmapEncoder(); 
    foreach (var bmp in bitmapList) 
    { 
     var hbmp = bmp.GetHbitmap(); 
     var src = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbmp, IntPtr.Zero, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); 
     gEnc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(src)); 
    } 

    using (FileStream fs = new FileStream(@"C:\panel1.gif", FileMode.Create)) 
    { 
     gEnc.Save(fs); 
    } 
    bitmapList.Clear(); 
} 
+0

在舊版本中,我使用定時器來製作動畫,並且我捕獲屏幕的每一幀。將它合併並導出到gif文件。現在我使用一個庫來支持動畫控制,使動畫變得清晰快捷。我只是聲明變量並使用。所以我不能通過計時器來屏幕。我選擇一個解決方案記錄面板並導出到GIF文件。 –

+0

關於您的解決方案。每張動畫我都無法拍攝。你能告訴我一個我們錄製面板的解決方案嗎?我們可以使用任何工具來實現它:框架,像bandicam這樣的軟件,......任何要做的事情。你能幫我嗎? –

相關問題