Spout.NET
1.0.0
Spout.NET は、Windows 用のビデオ フレーム共有システムである Spout2 の C# .NET 実装です。
Spout.NET は NuGet からインストールできます。
Install-Package Spout.NET
Spout.NET
はNuGet 3.3
以降 (つまりPackageReference
) が必要であることに注意してください。プロジェクトでpackages.config
使用している場合は、パッケージを PackageReference に移行してください。
このマッピング ライブラリの API は Spout SDK と完全に一致しているため、開発のために Spout SDK ドキュメントを参照できます。マーシャル クラスを使用すると、安全でないコードを回避できます。
.NET Framework コンソール プロジェクトを作成します。
ビルド構成のターゲットを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 ;
}
}
}
}
}
マサチューセッツ工科大学