2009-03-20 5 views
4

Je voudrais savoir s'il existe un moyen de capturer un pour capturer une vidéo (screencast) de mon bureau avec .NET? Je ne cherche pas un logiciel de screencast, mais simplement une technique qui me permettrait de générer moi-même une vidéo de mon bureau.Comment capturer une vidéo de mon bureau avec .NET?

Je pensais que de prendre des captures d'écran multiples, mais je ne suis pas sûr de la façon dont je pourrais générer une programmation vidéo avec une séquence d'images ...

Est-ce que quelqu'un a une idée?

Merci!

Répondre

1

Oui, il y a plusieurs façons de le faire. C'est une méthode très simple utilisant WPF. Ça marche, je l'ai déjà utilisé.

http://www.sythe.org/showthread.php?t=175353

Sur le site:

Créer une nouvelle application WPF, ajouter une référence à System.Drawing.dll et System.Windows.Forms.dll. Utilisez les méthodes que vous attendez, Stat, Stop et Save.

Public Class ScreenRecorder 

    Private Shared tempDir As String = My.Computer.FileSystem.SpecialDirectories.Temp & "\snapshot\" 
    Private Shared snap As New System.Threading.Thread(AddressOf Snapshot) 
    Private Shared _Bounds As System.Drawing.Rectangle = System.Windows.Forms.Screen.PrimaryScreen.Bounds 
    Public Shared Property Bounds() As System.Drawing.Rectangle 
     Get 
      Return _Bounds 
     End Get 
     Set(ByVal value As System.Drawing.Rectangle) 
      _Bounds = value 
     End Set 
    End Property 
    Private Shared Sub Snapshot() 
     If Not My.Computer.FileSystem.DirectoryExists(tempDir) Then _ 
      My.Computer.FileSystem.CreateDirectory(tempDir) 
     Dim Co As Integer = 0 
     Do 
      Co += 1 
      System.Threading.Thread.Sleep(50) 
      Dim X As New System.Drawing.Bitmap(_Bounds.Width, _Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb) 
      Using G = System.Drawing.Graphics.FromImage(X) 
       G.CopyFromScreen(_Bounds.Location, New System.Drawing.Point(), _Bounds.Size) 
       Dim CurBounds As New System.Drawing.Rectangle(System.Windows.Forms.Cursor.Position - Bounds.Location, System.Windows.Forms.Cursor.Current.Size) 
       Forms.Cursors.Default.Draw(G, CurBounds) 
      End Using 
      Dim FS As New IO.FileStream(tempDir & FormatString(Co.ToString, 5, "0"c) & ".png", IO.FileMode.OpenOrCreate) 
      X.Save(FS, System.Drawing.Imaging.ImageFormat.Png) 
      X.Dispose() 
      FS.Close() 
     Loop 
    End Sub 
    Public Shared Sub ClearRecording() 
     If My.Computer.FileSystem.DirectoryExists(tempDir) Then _ 
     My.Computer.FileSystem.DeleteDirectory(tempDir, FileIO.DeleteDirectoryOption.DeleteAllContents) 
     My.Computer.FileSystem.CreateDirectory(tempDir) 
    End Sub 
    Public Shared Sub Save(ByVal Output As String) 
     Dim G As New Windows.Media.Imaging.GifBitmapEncoder 

     Dim X As New List(Of IO.FileStream) 
     For Each Fi As String In My.Computer.FileSystem.GetFiles(tempDir, FileIO.SearchOption.SearchTopLevelOnly, "*.png") 
      Dim TempStream As New IO.FileStream(Fi, IO.FileMode.Open) 
      Dim Frame = Imaging.BitmapFrame.Create(TempStream) 
      X.Add(TempStream) 
      G.Frames.Add(Frame) 
     Next 
     Dim FS As New IO.FileStream(Output, IO.FileMode.OpenOrCreate) 
     G.Save(FS) 
     FS.Close() 

     For Each St As IO.FileStream In X 
      St.Close() 

     Next 

    End Sub 
    Public Shared Sub Start() 
     snap = New System.Threading.Thread(AddressOf Snapshot) 
     snap.Start() 
    End Sub 
    Public Shared Sub [Stop]() 
     snap.Abort() 
    End Sub 
    Private Shared Function FormatString(ByVal S As String, ByVal places As Integer, ByVal character As Char) As String 
     If S.Length >= places Then Return S 
     For X As Integer = S.Length To places 
      S = character & S 
     Next 
     Return S 
    End Function 

End Class 

Voici une autre méthode utilisant Managed DirectX

http://www.mdxinfo.com/resources/screencapture.php

Une autre ressource:

http://www.codeproject.com/KB/audio-video/CaptureScreenAsVideo.aspx

+1

J'aime cette façon! Mais il produit un gigantesque fichier GIF ... – Martin

+0

Oui, ça marche mais ça marche. – BobbyShaftoe

+0

Ca le fait ... mais le fichier est très gros pour mon besoin. Une idée de comment je pourrais convertir ce GIF en MPG, Silverlight, ou quelque chose comme ça? – Martin

0

je crois que je l'ai fait quelque chose de semblable à cela un tout en utilisant il y a le DirectShowNet library Cela peut vous aider.

Questions connexes