Spout.NET es una implementación de C# .NET para Spout2, un sistema para compartir fotogramas de vídeo para Windows.
Puede instalar Spout.NET desde NuGet.
Install-Package Spout.NET
Tenga en cuenta que Spout.NET
requiere NuGet 3.3
o superior (en otras palabras, PackageReference
). Si su proyecto utiliza packages.config
, migre sus paquetes a PackageReference.
La API de esta biblioteca de mapeo es completamente consistente con Spout SDK, por lo que puede consultar la documentación de Spout SDK para su desarrollo. Puede utilizar Marshal Class para evitar código inseguro.
Cree un proyecto de consola .NET Framework.
Vuelva a orientar la configuración de compilación a x64
.
Agregue los siguientes paquetes nuget.
Install-Package Spout.NET
Active Allow Unsafe Code
en la configuración del proyecto.
Coloque el siguiente código en 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 ;
}
}
}
}
}
MIT