Spout.NET
1.0.0
Spout.NET هو تطبيق C# .NET لـ Spout2، وهو نظام مشاركة إطار فيديو لنظام التشغيل Windows.
يمكنك تثبيت Spout.NET من NuGet.
Install-Package Spout.NET يرجى ملاحظة أن Spout.NET يتطلب NuGet 3.3 أو أعلى (وبعبارة أخرى، PackageReference ). إذا كان مشروعك يستخدم packages.config ، فيرجى ترحيل الحزم الخاصة بك إلى PackageReference.
تتوافق واجهة برمجة التطبيقات (API) الخاصة بمكتبة التعيين هذه تمامًا مع Spout SDK، لذا يمكنك الرجوع إلى وثائق Spout SDK للتطوير. يمكنك استخدام Marshal Class لتجنب التعليمات البرمجية غير الآمنة.
قم بإنشاء مشروع .NET Framework Console.
أعد استهداف تكوين البناء إلى x64 .
أضف حزم nuget التالية.
Install-Package Spout.NET قم بتشغيل Allow Unsafe Code في تكوين المشروع.
ضع الكود التالي في Program.cs .
using System ;
using System . IO ;
using System . Threading ;
using OpenGL ;
using Spout . Interop ;
namespace SpoutTest
{
class Program
{
static unsafe void Main ( string [ ] args )
{
using ( DeviceContext deviceContext = DeviceContext . Create ( ) ) // Create the DeviceContext
{
IntPtr glContext = IntPtr . Zero ;
glContext = deviceContext . CreateContext ( IntPtr . Zero ) ;
deviceContext . MakeCurrent ( glContext ) ; // Make this become the primary context
SpoutSender sender = new SpoutSender ( ) ;
sender . CreateSender ( "CsSender" , 640 , 360 , 0 ) ; // Create the sender
byte [ ] data = new byte [ 640 * 360 * 4 ] ;
int i = 0 ;
fixed ( byte * pData = data ) // Get the pointer of the byte array
while ( true )
{
for ( int j = 0 ; j < 640 * 360 * 4 ; j += 4 )
{
data [ j ] = i == 0 ? byte . MaxValue : byte . MinValue ;
data [ j + 1 ] = i == 1 ? byte . MaxValue : byte . MinValue ;
data [ j + 2 ] = i == 2 ? byte . MaxValue : byte . MinValue ;
data [ j + 3 ] = byte . MaxValue ;
}
Console . WriteLine ( $ "Sending (i = { i } )" ) ;
sender . SendImage (
pData , // Pixels
640 , // Width
360 , // Height
Gl . RGBA , // GL_RGBA
true , // B Invert
0 // Host FBO
) ;
Thread . Sleep ( 1000 ) ; // Delay
if ( i < 2 ) i ++ ;
else i = 0 ;
}
}
}
}
}معهد ماساتشوستس للتكنولوجيا