首页 / C# / c# – 如何使用.NET捕获桌面视频?
c# – 如何使用.NET捕获桌面视频?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 如何使用.NET捕获桌面视频?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3080字,纯文字阅读大概需要5分钟。
内容图文
![c# – 如何使用.NET捕获桌面视频?](/upload/InfoBanner/zyjiaocheng/768/1908ecd2bb8d4e77a01b638e1bf8ecab.jpg)
我想知道是否有任何方法可以捕获一个用.NET捕获我的桌面视频(截屏视频)?我不是在寻找一个截屏软件,而只是一种技术,可以让我自己生成一个桌面视频.
我想过拍多张截图,但我不确定如何以编程方式生成带有一系列图像的视频……
有人有想法吗?
谢谢!
解决方法:
是的,有很多方法可以做到这一点.这是一个使用WPF的非常简单的方法.它有效,我以前用过它.
http://www.sythe.org/showthread.php?t=175353
从网站:
创建一个新的WPF应用程序,添加对System.Drawing.dll和System.Windows.Forms.dll的引用.使用您期望的方法,Stat,Stop和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
这是使用Managed DirectX的另一种方法
http://www.mdxinfo.com/resources/screencapture.php
另一种资源:
http://www.codeproject.com/KB/audio-video/CaptureScreenAsVideo.aspx
内容总结
以上是互联网集市为您收集整理的c# – 如何使用.NET捕获桌面视频?全部内容,希望文章能够帮你解决c# – 如何使用.NET捕获桌面视频?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。