Spout.NET é uma implementação C# .NET para Spout2, um sistema de compartilhamento de quadros de vídeo para Windows.
Você pode instalar o Spout.NET do NuGet.
Install-Package Spout.NET
Observe que Spout.NET
requer NuGet 3.3
ou superior (em outras palavras, PackageReference
). Se o seu projeto usa packages.config
, migre seus pacotes para PackageReference.
A API desta biblioteca de mapeamento é totalmente consistente com o Spout SDK, portanto, você pode consultar a documentação do Spout SDK para desenvolvimento. Você pode usar a classe Marshal para evitar códigos inseguros.
Crie um projeto do console .NET Framework.
Redirecione a configuração de compilação para x64
.
Adicione os seguintes pacotes de nuget.
Install-Package Spout.NET
Ative Allow Unsafe Code
na configuração do projeto.
Coloque o seguinte código em 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