docs: 同步需求、架构、模块清单、竞品分析与多语言 README
大石头 authored at 2026-11-28 21:46:17 大石头 committed at 2026-11-28 21:48:03
19.05 KiB
NewLife.Imaging
# NewLife.Imaging - 純受控影像基礎庫 ![GitHub top language](https://img.shields.io/github/languages/top/newlifex/NewLife.Imaging?logo=github) ![GitHub License](https://img.shields.io/github/license/NewLifeX/NewLife.Imaging?logo=github) ![NuGet Downloads](https://img.shields.io/nuget/dt/NewLife.Imaging?logo=nuget) ![NuGet](https://img.shields.io/nuget/v/NewLife.Imaging?logo=nuget) ![NuGet prerelease](https://img.shields.io/nuget/vpre/NewLife.Imaging?label=dev%20nuget&logo=nuget) [![test](https://github.com/NewLifeX/NewLife.Imaging/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/NewLifeX/NewLife.Imaging/actions/workflows/test.yml) ![locales](https://img.shields.io/badge/locales-11-2ea44f?logo=dotnet) ![platform](https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS%20%7C%20Android%20%7C%20iOS-blue) ![arch](https://img.shields.io/badge/arch-AnyCPU-orange) [![contributors](https://img.shields.io/github/contributors/NewLifeX/NewLife.Imaging?logo=github)](https://github.com/NewLifeX/NewLife.Imaging/graphs/contributors) <!-- lang:start --> 🌐 [English](/NewLife/NewLife.Imaging/Blob/master/README.md) | [简体中文](/NewLife/NewLife.Imaging/Blob/master/README.zh-CN.md) | [Español](/NewLife/NewLife.Imaging/Blob/master/README.es.md) | [Deutsch](/NewLife/NewLife.Imaging/Blob/master/README.de.md) | [日本語](/NewLife/NewLife.Imaging/Blob/master/README.ja.md) | [Français](/NewLife/NewLife.Imaging/Blob/master/README.fr.md) | [Português](/NewLife/NewLife.Imaging/Blob/master/README.pt.md) | [Русский](/NewLife/NewLife.Imaging/Blob/master/README.ru.md) | [한국어](/NewLife/NewLife.Imaging/Blob/master/README.ko.md) | [العربية](/NewLife/NewLife.Imaging/Blob/master/README.ar.md) <!-- lang:end --> > 本翻譯可能落後,以 [English README](/NewLife/NewLife.Imaging/Blob/master/README.md) 為準。 純受控 .NET 影像基礎庫:JPEG、PNG、GIF、BMP、ICO、QOI、PNM 編解碼,像素處理、繪製基本元件與中繼資料,預設零原生相依性。 原始碼:https://github.com/NewLifeX/NewLife.Imaging NuGet:`NewLife.Imaging` ## 快速開始 ```bash dotnet add package NewLife.Imaging ``` ```csharp using NewLife.Imaging; var frame = ImageFrame.Create(640, 480, PixelFormat.Rgb24); var row = frame.GetRowSpan(0); row[0] = 255; Console.WriteLine(ImageInfo.From(frame)); // 透過 SIMD 橋接套件解碼 JPEG、PNG、WebP 或 AVIF var photo = NewLife.Imaging.Codecs.ImageCodecs.Decode(File.ReadAllBytes("photo.jpg")); // 產生登入頁驗證碼 var captcha = NewLife.Imaging.Drawing.CaptchaGenerator.Generate(); File.WriteAllBytes("captcha.png", captcha.ToPng()); ``` 目標框架:`net45`、`netstandard2.0`、`netstandard2.1`、`net8.0`、`net10.0`。 ## 功能特色 已實作像素模型、編解碼契約、像素處理、繪製基本元件與純受控編解碼器。JPEG、PNG、GIF、BMP、ICO、QOI、PNM 在主套件內完成編碼與解碼;TIFF 與 WebP 解碼計畫在 v1.1 提供。中繼資料涵蓋 EXIF 方向/DPI、PNG 文字區塊、JPEG 註解與 ICC 原始設定。 <details> <summary><b>影像編解碼</b></summary> | 能力 | 帶來的價值 | | --- | --- | | 影像影格模型 | 單一扁平緩衝區、一種像素格式、一套行距約定,所有 NewLife 程式庫共用 | | 像素格式 | Gray8、Rgb24、Bgr24、Rgba32、Bgra32,位元組配置明確 | | 編解碼契約 | `IImageDecoder` / `IImageEncoder` 與執行緒安全的 `ImageCodecs` 登錄表,支援副檔名與魔術數字查找 | | JPEG、PNG、GIF、BMP、ICO、QOI、PNM | 純受控編碼與解碼 | | WebP、TIFF | 純受控編碼已實作;TIFF 為基準無壓縮 | | 格式識別 | 透過 `FindByData` 對全部支援格式做魔術數字識別 | </details> <details> <summary><b>影像處理</b></summary> 已實作:像素格式轉換、最近鄰與雙線性縮放、裁剪、直角旋轉、翻轉、灰階化、Otsu 二值化與亮度/對比調整;其餘為規劃中。 | 能力 | 帶來的價值 | | --- | --- | | 像素格式轉換 | 在 RGB、BGR、RGBA、BGRA 與灰階之間轉換,不離開統一模型 | | 縮放與裁剪 | 最近鄰、雙線性、雙三次與面積平均;矩形裁剪與畫布擴充 | | 旋轉與翻轉 | 直角旋轉走無損快速路徑,另支援任意角旋轉 | | 色彩調整 | 依通道設定亮度、對比、飽和度與伽瑪 | | 灰階與閾值 | 加權灰階、固定閾值與 Otsu 二值化 | | 卷積 | 均值/高斯模糊、銳化與 Sobel 邊緣偵測 | | Alpha 合成 | 預乘、反預乘與常用 Porter-Duff 模式 | | 直方圖與量化 | 自動色階、等化、調色盤量化與抖動 | </details> <details> <summary><b>繪製基本元件</b></summary> 已實作:畫布清除與填滿、Bresenham 直線、矩形、8x8 點陣文字、影像區塊傳送與驗證碼產生;其餘為規劃中。 | 能力 | 帶來的價值 | | --- | --- | | 基本圖形 | 直接畫在影像影格上的直線、矩形、圓、橢圓與多邊形 | | 反鋸齒 | 依覆蓋率混合線條與多邊形邊緣 | | 點陣字型 | 內建 8x16 ASCII 字型,支援縮放與前景/背景色 | | 影像合成 | 區塊傳送、縮放繪製、Alpha 混合與不透明覆蓋 | | 驗證碼 | 隨機字元疊加干擾線與雜訊點,可直接用於後台登入頁 | | 裁剪與遮罩 | 矩形裁剪區與單通道遮罩 | | 漸層 | 支援多色停駐點的線性與徑向漸層 | </details> <details> <summary><b>中繼資料</b></summary> | 能力 | 帶來的價值 | | --- | --- | | EXIF | 讀寫相機、時間、曝光與 GPS 標籤 | | ICC 設定檔 | 讀取設定描述,編碼時可嵌入原始設定資料 | | DPI 與實體尺寸 | 附單位的水平與垂直解析度 | | 方向 | 讀取 EXIF 方向並自動旋正像素 | | 動畫資訊 | GIF 與 WebP 的影格延遲、循環次數與處置方式 | | 文字區塊 | PNG tEXt/zTXt/iTXt 與 JPEG COM 標記 | </details> <details> <summary><b>配接器</b></summary> | 能力 | 帶來的價值 | | --- | --- | | System.Drawing | 面向 Windows 舊程式的 `Bitmap` 與 `ImageFrame` 互轉 | | WPF、WinUI、Avalonia | 獨立套件中的 UI 點陣圖互轉 | | SkiaSharp | 面向既有 Skia 技術棧的 `SKBitmap`、`SKImage` 互轉 | | 內建編解碼器 | JPEG、PNG、GIF、BMP、ICO、QOI、PNM 均在主套件內,無第三方編解碼相依性 | | VideoFrame | 視訊影格配接實作於 NewLife.Video 儲存庫 | | Office、Cube、Vision | 文件、管理後台與視覺管線共用的像素模型 | </details> ## 生態版圖 NewLife 生態系按相依分層,各專案獨立版本、獨立發行。下面的版圖在所有 NewLife 儲存庫中逐字一致;每個專案連結到程式碼儲存庫與主 NuGet 套件。 | 專案 | 一句話定位 | 下載量 | | --- | --- | --- | | **基礎底座** | | | | [NewLife.Core](https://github.com/NewLifeX/X) | 日誌、設定、快取、網路、序列化、排程與 APM 追蹤。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Core?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Core) | | [NewLife.XCode](https://github.com/NewLifeX/NewLife.XCode) | 資料中介層:單表百億級、自動分表、讀寫分離,支援 10 多種資料庫。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.XCode?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.XCode) | | [NewLife.Net](https://github.com/NewLifeX/NewLife.Net) | 高效能網路庫:單機 177 萬 pps、14.5 Gbps(TCP 1KB,2026-10 實測),400 萬 Tcp 長連線。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Net?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Net) | | [NewLife.Remoting](https://github.com/NewLifeX/NewLife.Remoting) | 協定通訊與 RPC 框架,面向 CS 應用程式與物聯網裝置。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Remoting?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Remoting) | | [NewLife.Agent](https://github.com/NewLifeX/NewLife.Agent) | 將 .NET 應用程式安裝為作業系統常駐服務:Windows 服務與 Linux systemd。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Agent?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Agent) | | [NewLife.Templates](https://github.com/NewLifeX/NewLife.Zero) | `dotnet new` 專案範本:主控台、Web、API、服務、資料與物聯網。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Templates?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Templates) | | **資料儲存與訊息** | | | | [NewLife.Redis](https://github.com/NewLifeX/NewLife.Redis) | Redis 用戶端:微秒級延遲、百萬級吞吐,內建訊息佇列。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Redis?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Redis) | | [NewLife.RocketMQ](https://github.com/NewLifeX/NewLife.RocketMQ) | 純受控 RocketMQ 用戶端,支援 Apache RocketMQ 與阿里雲訊息佇列。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.RocketMQ?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.RocketMQ) | | [NewLife.MQTT](https://github.com/NewLifeX/NewLife.MQTT) | MQTT 用戶端與服務端,含阿里雲物聯網接入。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.MQTT?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.MQTT) | | [NewLife.NovaDb](https://github.com/NewLifeX/NewLife.NovaDb) | C# 混合式資料庫:內嵌或網路雙模,關係型、時序、訊息佇列與 KV 於一體。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.NovaDb?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.NovaDb) | | [NewLife.MySql](https://github.com/NewLifeX/NewLife.MySql) | 建構於 NewLife 資料堆疊之上的 MySql 驅動與輔助層。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.MySql?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.MySql) | | [NewLife.TDengine](https://github.com/NewLifeX/NewLife.TDengine) | 純託管 TDengine ADO.NET 驅動:REST、WebSocket 與原生 RPC 三種連線方式,零本機相依。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.TDengine?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.TDengine) | | [NewLife.Presto](https://github.com/NewLifeX/NewLife.Presto) | 純 C# Presto/Trino ADO.NET 驅動,零第三方相依,支援 XCode ORM 整合。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Presto?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Presto) | | **Web 與分散式** | | | | [NewLife.Cube](https://github.com/NewLifeX/NewLife.Cube) | 快速後台開發框架:權限、SSO、OAuth 服務端與 CRUD 樣板。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Cube?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Cube) | | [NewLife.Cube.React](https://github.com/NewLifeX/NewLife.Cube.React) | 魔方前後端分離範例:WebAPI 後端 + Swagger + React/Vue/Blazor 前端。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Cube.React?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Cube.React) | | [Stardust](https://github.com/NewLifeX/Stardust) | 分散式服務平台:節點管理、APM、設定中心、註冊中心與發佈中心。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Stardust?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Stardust) | | [AntJob](https://github.com/NewLifeX/AntJob) | 分散式任務與即時資料排程平台,支援分片、重試與回溯補算。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.AntJob?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.AntJob) | | **AI 與視覺** | | | | [NewLife.AI](https://github.com/NewLifeX/NewLife.AI) | 統一接入 46 家大模型服務商,附帶開箱即用的 ChatAI Web 對話應用。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.AI?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.AI) | | [NewLife.Imaging](https://github.com/NewLifeX/NewLife.Imaging) | 純託管影像基礎庫:像素模型、編解碼契約、繪製與中繼資料,零原生相依。 | — | | [NewLife.Vision](https://github.com/NewLifeX/NewLife.Vision) | 視覺演算法庫:OCR、條碼、目標偵測與人臉辨識,建構於 NewLife.Imaging 之上。 | — | | [NewLife.ML](https://github.com/NewLifeX/NewLife.ML) | 面向 .NET 的表格機器學習:把資料庫表與 Excel 變成可部署的預測與分類模型。 | — | | **工業與物聯網** | | | | [NewLife.IoT](https://github.com/NewLifeX/NewLife.IoT) | 物聯網標準庫,定義通訊協定契約與裝置抽象。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.IoT?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.IoT) | | [NewLife.Modbus](https://github.com/NewLifeX/NewLife.Modbus) | 建構於 NewLife.IoT 之上的 Modbus TCP/RTU/ASCII 實作。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Modbus?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Modbus) | | [NewLife.Siemens](https://github.com/NewLifeX/NewLife.Siemens) | 建構於 NewLife.IoT 之上的西門子 PLC 協定。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Siemens?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Siemens) | | [NewLife.Omron](https://github.com/NewLifeX/NewLife.Omron) | 建構於 NewLife.IoT 之上的歐姆龍 PLC 協定。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Omron?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Omron) | | [NewLife.Melsec](https://github.com/NewLifeX/NewLife.Melsec) | 建構於 NewLife.IoT 之上的三菱 Melsec PLC 協定。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Melsec?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Melsec) | | [NewLife.Schneider](https://github.com/NewLifeX/NewLife.Schneider) | 施耐德 PLC 通訊驅動,基於 Modbus TCP。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Schneider?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Schneider) | | [NewLife.OPC](https://github.com/NewLifeX/NewLife.OPC) | 工業資料存取的 OPC 用戶端。 | — | | [NewLife.BACnet](https://github.com/NewLifeX/NewLife.BACnet) | BACnet 樓宇自動化協定堆疊。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.BACnet?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.BACnet) | | [NewLife.LoRa](https://github.com/NewLifeX/NewLife.LoRa) | 超低功耗物聯網遠端通訊協定 LoRaWAN。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.LoRa?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.LoRa) | | [ZeroIoT](https://github.com/NewLifeX/ZeroIoT) | 開源輕量級物聯網平台,含閘道與裝置管理。 | — | | **車聯網** | | | | [NewLife.JT808](https://github.com/NewLifeX/NewLife.JT808) | JT/T 808 車輛定位協定:70+ 訊息體,涵蓋 2011/2013/2019 三個版本。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.JT808?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.JT808) | | [NewLife.JT809](https://github.com/NewLifeX/NewLife.JT809) | JT/T 809 部標平台互聯協定,面向運輸管理部門。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.JT809?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.JT809) | | [NewLife.JT1078](https://github.com/NewLifeX/NewLife.JT1078) | JT/T 1078 車載視訊:RTP 解析、FLV/fMP4 轉封裝與直播推送。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.JT1078?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.JT1078) | | **領域元件** | | | | [NewLife.Office](https://github.com/NewLifeX/NewLife.Office) | 一個套件涵蓋 Excel、Word、PPT、PDF 等 15+ 文件格式。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Office?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Office) | | [NewLife.Audio](https://github.com/NewLifeX/NewLife.Audio) | 跨平台音訊:編解碼、裝置 IO、DSP、容器與串流處理。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Audio?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Audio) | | [NewLife.Video](https://github.com/NewLifeX/NewLife.Video) | 視訊編解碼、封裝格式、影格處理與串流。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Video?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Video) | | [NewLife.Map](https://github.com/NewLifeX/NewLife.Map) | 百度/高德/騰訊/天地圖統一介面,支援地理編碼與座標轉換。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Map?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Map) | | [NewLife.IP](https://github.com/NewLifeX/NewLife.IP) | IPv4 歸屬地:離線記憶體映射資料庫 + 線上 API 雙來源。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.IP?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.IP) | | [NewLife.Holiday](https://github.com/NewLifeX/NewLife.Holiday) | 中國假期識別庫:內建每年假期與調休資料,支援農曆節日,完全離線。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.Holiday?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.Holiday) | | **工具與產品** | | | | [CrazyCoder](https://github.com/NewLifeX/XCoder) | 開發者工具箱:網路、序列埠、加解密、正規表示式、Modbus 與 MQTT。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.XCoder?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.XCoder) | | [NewLife.UnitTest](https://github.com/NewLifeX/NewLife.UnitTest) | 單元測試擴充庫:測試基類、資料驅動與相依性注入輔助。 | [![NuGet](https://img.shields.io/nuget/dt/NewLife.UnitTest?style=flat-square&logo=nuget&label=downloads)](https://www.nuget.org/packages/NewLife.UnitTest) | | [GitCandy](https://github.com/NewLifeX/GitCandy) | 自架 Git 原始碼管理系統。 | — | | [LuckyClover](https://github.com/NewLifeX/LuckyClover) | 從較舊的宿主啟動時,自動安裝相符的 .NET 執行階段。 | — | > 徽章取各專案主套件;主題套件、擴充套件與衛星套件見對應 NuGet 頁面。未在表中列出的 30 多個套件(FTP、Office 擴充、各類協定驅動等)見 [NewLifeX 組織](https://github.com/NewLifeX) 與 [newlifex.com](https://newlifex.com)。 ## 說明文件 | 文件 | 說明 | | --- | --- | | [需求文件](/NewLife/NewLife.Imaging/Blob/master/Doc/需求文档.md) | 願景、核心目標與模組劃分 | | [功能清單](/NewLife/NewLife.Imaging/Blob/master/Doc/模块清单.md) | 實作、測試與註解三維狀態 | | [架構設計](/NewLife/NewLife.Imaging/Blob/master/Doc/架构设计.md) | 工程結構、邊界與關鍵設計決策 | | [競品分析](/NewLife/NewLife.Imaging/Blob/master/Doc/竞品分析.md) | 與 ImageSharp、SkiaSharp、Magick.NET 等方案比較 | | [更新記錄](/NewLife/NewLife.Imaging/Blob/master/Doc/ChangeLog.md) | 版本發佈歷史 | | [範例](/NewLife/NewLife.Imaging/Blob/master/Samples/ImagingDemo) | 可執行的主控台範例 | ## 參與貢獻 歡迎提交 Issue 與 Pull Request。提交前請先執行與 CI 相同的檢查: ```bash dotnet build -c Release dotnet test -c Release pwsh -File Tools/Scripts/check-readmes.ps1 ``` ## 授權 [MIT 授權](/NewLife/NewLife.Imaging/Blob/master/LICENSE)