首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用.NET捕获我的桌面视频?

如何使用.NET捕获我的桌面视频?
EN

Stack Overflow用户
提问于 2009-03-20 03:04:30
回答 2查看 5K关注 0票数 4

我想知道是否有任何方法可以使用.NET捕获我的桌面的视频(截屏)?我不是在寻找一个截屏软件,而是一个简单的技术,可以让我自己生成我的桌面视频。

我想过拍摄多张截图,但我不确定如何通过编程方式生成包含一系列图像的视频……

有没有人有主意?

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-03-20 03:07:31

是的,有很多方法可以做到这一点。这是一个使用WPF的非常简单的方法。它起作用了,我以前用过。

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

从该站点:

创建一个新的WPF应用程序,添加对System.Drawing.dll和System.Windows.Forms.dll的引用。如您所愿,使用Stat、Stop和Save方法。

代码语言:javascript
复制
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

下面是使用托管DirectX的另一种方法

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

另一个资源:

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

票数 1
EN

Stack Overflow用户

发布于 2009-03-20 03:07:46

我想我之前用DirectShowNet library做过类似的事情。这可能会对你有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/664841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档