TouchSocketPro.Dmtp.PixStream 5.0.0-beta.76

Prefix Reserved
This is a prerelease version of TouchSocketPro.Dmtp.PixStream.
dotnet add package TouchSocketPro.Dmtp.PixStream --version 5.0.0-beta.76
                    
NuGet\Install-Package TouchSocketPro.Dmtp.PixStream -Version 5.0.0-beta.76
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TouchSocketPro.Dmtp.PixStream" Version="5.0.0-beta.76" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TouchSocketPro.Dmtp.PixStream" Version="5.0.0-beta.76" />
                    
Directory.Packages.props
<PackageReference Include="TouchSocketPro.Dmtp.PixStream" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TouchSocketPro.Dmtp.PixStream --version 5.0.0-beta.76
                    
#r "nuget: TouchSocketPro.Dmtp.PixStream, 5.0.0-beta.76"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TouchSocketPro.Dmtp.PixStream@5.0.0-beta.76
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TouchSocketPro.Dmtp.PixStream&version=5.0.0-beta.76&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=TouchSocketPro.Dmtp.PixStream&version=5.0.0-beta.76&prerelease
                    
Install as a Cake Tool

TouchSocketPro.Dmtp.PixStream

基于 DMTP 协议的像素流图像传输扩展(专业版),支持裁剪、缩放和 JPEG 压缩。

功能特性

  • 支持服务端持续采集相机画面或BMP图像
  • 客户端主动拉取图像帧
  • 首次请求:传输完整帧(Full Frame)
  • 后续请求:仅传输变化块的增量差异(Delta Frame),由客户端本地合成完整帧
  • 支持路由转发,可跨DMTP节点获取图像

像素格式

BGR24,每像素 3 字节,从上到下按行存储。输入可以通过 stride 指定包含行尾填充的每行字节数。

使用方式

服务端(图像提供方)

using var provider = new PixStreamProvider();
using var service = new TcpDmtpService();
await service.SetupAsync(new TouchSocketConfig()
    .SetListenIPHosts(7789)
    .ConfigurePlugins(plugins =>
    {
        plugins.UseDmtpPixStream(options => options.Provider = provider);
        plugins.Add(typeof(IDmtpPixStreamCreatingPlugin),
            async (IDmtpActorObject client, DmtpPixStreamCreatingEventArgs e) =>
            {
                // 在此按业务规则检查 client、e.Metadata 等,再决定是否允许创建。
                e.IsPermitOperation = true;
                await e.InvokeNext();
            });
    }));
await service.StartAsync();

// UpdateFrame 在返回前完成复制,调用方随后可以复用原始缓冲区。
// stride 省略或传 0 表示 width * 3。
provider.UpdateFrame(pixels, width, height, stride);

客户端(图像消费方)

using var client = new TcpDmtpClient();
await client.SetupAsync(new TouchSocketConfig()
    .SetRemoteIPHost("127.0.0.1:7789")
    .ConfigurePlugins(plugins => plugins.UseDmtpPixStream()));
await client.ConnectAsync();

var session = await client.GetDmtpPixStreamActor()
    .CreatePixStreamSessionAsync(new PixStreamRequest { Quality = 80 });
session.OnReceived = frame =>
{
    using (frame)
    {
        foreach (var block in frame.Blocks)
        {
            // 将 block.Bgr24Data 绘制到 (block.X, block.Y)。
            // 首帧是完整帧;增量帧只包含变化块,应保留未改变区域。
            // frame.Dispose() 后内存失效,异步保留时需自行复制。
        }
    }
    return Task.CompletedTask;
};
session.Start();

// 停止使用时:
await session.CloseAsync("Completed", CancellationToken.None);

路由传输使用 CreatePixStreamSessionAsync(targetId, request)。 OffsetX、OffsetY 指定裁剪起点,裁剪范围延伸至原图右下角;同时设置正数 Width 和 Height 可缩放输出。 Quality 为 0 时传输原始 BGR24,为 1–100 时使用 JPEG;EnableDeltaTransfer 控制增量传输。

图像依赖

JPEG 编解码及缩放使用 MIT 许可证的 SkiaSharp。公共 API 只接收 BGR24 内存,无需暴露图像库类型。 NuGet 依赖包含 Windows、macOS 和 Linux 的 Skia 本机运行库;部署时应保留匹配目标系统及架构的本机资产。

说明文档

https://touchsocket.net/

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0-beta.76 45 11/29/2026
5.0.0-beta.28 53 11/24/2026
5.0.0-beta.11 64 11/14/2026
5.0.0-beta.5 62 11/12/2026
4.3.11 163 10/25/2026
4.3.10 123 10/11/2026
4.3.9 134 9/17/2026
4.3.8 120 9/17/2026
4.3.7 128 9/10/2026
4.3.6 139 9/5/2026
4.3.5 138 9/5/2026
4.3.4 140 8/27/2026
4.3.3 139 8/22/2026
4.3.2 150 8/15/2026
4.3.1 149 8/9/2026
4.3.0 154 8/1/2026
4.2.18 153 7/26/2026
4.2.17 145 7/12/2026
4.2.16 147 7/5/2026
4.2.14 152 6/14/2026
Loading failed