2012-03-07 112 views
3

如何在C#中從流圖像(只有沒有聲音的圖像)構建視頻?從流圖像創建視頻c#

這裏是我的應用程序的一些代碼:

static int ii = 1; 
public void drawBitmap(byte[] data) 
{ 
    MemoryStream ms = new MemoryStream(data); 
    try 
    { 
     Bitmap b = new Bitmap(ms); 
     b.Save(@"c:\test\" + (ii++) + ".jpg"); 
     Image i = (Image)b; 
     pictureBox1.Image = i; 
     ii++; 
    } 
    catch (Exception e) 
    { 
    } 
} 
+2

普萊斯闡述。你想寫一個AVI,或只是以給定的幀速率顯示它們嗎? – 2012-03-07 19:24:45

+0

寫一個AVI並保存到我的桌面 謝謝 – user1245145 2012-03-07 19:28:22

+0

任何最終的解決方案,完整的源代碼示例? – Kiquenet 2013-11-28 20:43:24

回答

4

我用上面提到的包裝,像這樣:

private static void hejHopp() 
{ 
    //http://www.codeproject.com/Articles/7388/A-Simple-C-Wrapper-for-the-AviFile-Library 

    //myReadyNAS device, got files via FTP from my webcam 
    var jpgFileList = Directory.EnumerateFiles(sourcePath,"*.jpg"); 

    //load the first image 
    Bitmap bitmap = (Bitmap)Image.FromFile(jpgFileList.First()); 

    //create a new AVI file 
    AviManager aviManager = new AviManager(sourcePath + "\\tada.avi", false); 

    //add a new video stream and one frame to the new file 
    //set IsCompressed = false 
    VideoStream aviStream = aviManager.AddVideoStream(false, 2, bitmap); 

    jpgFileList.Skip(1).ToList().ForEach(file => 
    { 
     bitmap = (Bitmap)Bitmap.FromFile(file); 
     aviStream.AddFrame(bitmap); 
     bitmap.Dispose(); 
    }); 

    aviManager.Close(); 
} 
+0

包裝導致「訪問衝突」,任何解決方法的例外? – CodeIt 2017-02-15 16:38:52