Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,87 +1,150 @@
---
title: 使用 Aspose.BarCode for .NET 生成 DataMatrix 条形码
linktitle: 数据矩阵版本
date: 2026-08-22
description: 如何在 .NET 中使用 Aspose.BarCode 生成 DataMatrix 条形码。了解自定义尺寸、ECC 支持以及版本控制,轻松上手。
keywords:
- how to generate datamatrix
- DataMatrix barcode .NET
- Aspose.BarCode tutorial
lastmod: 2026-08-22
linktitle: DataMatrix 版本
og_description: 如何在 .NET 中快速生成 DataMatrix 条形码。本指南提供逐步创建、版本选择以及使用 Aspose.BarCode for
.NET 的 ECC 配置。
og_image_alt: Screenshot of DataMatrix barcode generated by Aspose.BarCode in a .NET
application
og_title: 如何使用 Aspose.BarCode for .NET 生成 DataMatrix 条形码
schemas:
- author: Aspose
dateModified: '2026-08-22'
description: How to generate DataMatrix barcodes in .NET using Aspose.BarCode. Learn
custom dimensions, ECC support, and version control in minutes.
headline: How to generate DataMatrix barcodes with Aspose.BarCode for .NET
type: TechArticle
- questions:
- answer: ECC (Error Correction Code) adds redundant data that lets scanners recover
the original message even if part of the symbol is damaged or dirty.
question: What is ECC in DataMatrix barcodes?
- answer: Yes, you can customize the dimensions of DataMatrix barcodes by setting
the number of rows and columns as demonstrated in the tutorial.
question: Can I generate DataMatrix barcodes with custom dimensions using Aspose.BarCode
for .NET?
- answer: 'You can download Aspose.BarCode for .NET from the **Aspose.BarCode .NET
download page**: [Aspose.BarCode .NET download page](https://releases.aspose.com/barcode/net/).'
question: Where can I download Aspose.BarCode for .NET?
- answer: Yes, you can access a free trial of Aspose.BarCode for .NET [here](https://releases.aspose.com/barcode/net/).
question: Is there a free trial available for Aspose.BarCode for .NET?
- answer: 'To get a temporary license for Aspose.BarCode for .NET, visit the temporary
license page: [temporary license page](https://purchase.aspose.com/temporary-license/).
You can also browse the full release catalog [here](https://releases.aspose.com/).'
question: How can I obtain a temporary license for Aspose.BarCode for .NET?
type: FAQPage
second_title: Aspose.BarCode .NET API
description: 了解如何使用 Aspose.BarCode for .NET 在 .NET 中生成 DataMatrix 条形码。自定义尺寸、ECC 支持等等。
weight: 12
tags:
- DataMatrix
- Aspose.BarCode
- .NET barcode generation
title: 如何使用 Aspose.BarCode for .NET 生成 DataMatrix 条形码
url: /zh/net/datamatrix-barcode-reading/datamatrix-versions/
weight: 12
---

{{< blocks/products/pf/main-wrap-class >}}
{{< blocks/products/pf/main-container >}}
{{< blocks/products/pf/tutorial-page-section >}}

# 使用 Aspose.BarCode for .NET 生成 DataMatrix 条形码
# 如何使用 Aspose.BarCode for .NET 生成 DataMatrix 条码

如果您正在寻找可靠的解决方案来在 .NET 应用程序中生成 DataMatrix 条形码,Aspose.BarCode for .NET 就是您的最佳选择。在本分步指南中,我们将引导您完成使用 Aspose.BarCode for .NET 创建 DataMatrix 条形码的过程。我们将把每个示例分解为多个步骤,确保您可以轻松地遵循
如果您需要在 .NET 应用程序中可靠地嵌入机器可读符号,**如何生成 DataMatrix 条码** 是一个常见需求。Aspose.BarCode for .NET 提供了一个完全托管的 API,处理从选择合适的 DataMatrix 版本到微调纠错级别的每一步——无需外部工具。在本教程中,我们将演示完整示例,解释每个设置的意义,并展示如何将结果保存为 PNG 或 JPEG 图像

## 先决条件
## 快速答案
- **哪个库可以创建 DataMatrix 条码?** Aspose.BarCode for .NET。
- **支持多少种 DataMatrix 版本?** 所有 30 种标准方形和矩形版本(从 10×10 到 144×144 模块)。
- **可以使用哪些 ECC 类型?** ECC200(默认)和 ECC140。
- **开发时需要许可证吗?** 免费的 30 天试用可用于测试;生产环境需要商业许可证。
- **可以在 .NET 6、.NET Core 或 .NET Framework 上运行吗?** 可以——Aspose.BarCode 支持 .NET Framework 4.5+、.NET Core 3.1+ 和 .NET 5/6+。

在我们深入研究代码之前,请确保您具备以下先决条件:
- 具有 .NET 支持的开发环境。
- Aspose.BarCode for .NET 的副本,您可以从以下位置下载[这个链接](https://releases.aspose.com/barcode/net/).
- C# 和 .NET 框架的基础知识。
## 什么是 DataMatrix 条码?
DataMatrix 条码是一种二维的方形或矩形矩阵,由黑白单元格组成,可存储多达 2,335 个字母数字字符。它在制造、物流和医疗保健等领域广泛用于标记小件物品,因为即使部分受损仍能保持可读性。

现在,让我们探索 DataMatrix 版本以及如何使用 Aspose.BarCode for .NET 生成它们。
## 为什么使用 Aspose.BarCode for .NET?
Aspose.BarCode 支持 **50+ 输出格式**(包括 PNG、JPEG、TIFF、SVG 和 PDF),并且能够生成 **所有 30 种 DataMatrix 版本**,无需将整幅图像加载到内存中,使您能够在处理大于 100 MB 文件的高吞吐服务中创建条码。

## 导入命名空间
## 前置条件

在深入代码之前,请确保具备以下前置条件:
- 支持 .NET 的开发环境(Visual Studio 2022、Rider 或 VS Code)。
- 一份 Aspose.BarCode for .NET,可从 **Aspose.BarCode .NET 下载页面** 下载:[Aspose.BarCode .NET 下载页面](https://releases.aspose.com/barcode/net/)。
- 基本的 C# 与 .NET 框架知识。

在任何 C# 项目中,导入必要的命名空间至关重要。对于 Aspose.BarCode,您需要包含以下内容:
现在,让我们一起探索 DataMatrix 版本以及如何使用 Aspose.BarCode for .NET 生成它们。

## 如何在 .NET 中生成 DataMatrix 条码?

加载 `BarcodeGenerator` 并使用 `EncodeTypes.DataMatrix` 类型,设置所需的版本和 ECC,然后调用 `Save` 写入图像文件。这一行代码模式适用于任意版本,并自动处理模块大小、安静区和图像渲染。

## 导入命名空间

`BarcodeGenerator` 是 Aspose.BarCode 用于创建条码图像的核心类。
```csharp
using Aspose.BarCode.Generation;
```
```csharp
using Aspose.BarCode.Generation;
```

该命名空间提供对`BarcodeGenerator`类,这对于生成条形码至关重要
`Aspose.BarCode.Generation` 命名空间提供对 `BarcodeGenerator` 类的访问,这是生成条码图像的主要类

现在,让我们将该示例分解为多个步骤
下面我们将示例拆分为多个步骤

## 第 1 步:设置目录路径
## 步骤 1:设置目录路径

首先定义要保存生成的 DataMatrix 条形码的目录路径
首先定义保存生成的 DataMatrix 条码的目录路径

```csharp
string path = "Your Directory Path";
```

代替`"Your Directory Path"`与您要保存条形码图像的实际路径
`"Your Directory Path"` 替换为实际的保存条码图像的路径

## 第 2 步:初始化条形码生成器
## 步骤 2:初始化条码生成器

创建一个实例`BarcodeGenerator`类并将条形码类型指定为`DataMatrix`。您还可以提供要在条形码中编码的数据
创建 `BarcodeGenerator` 实例并指定条码类型为 `DataMatrix`。您还可以提供要在条码中编码的数据

```csharp
using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.DataMatrix, "Åspóse.Barcóde©"))
{
//生成条形码的代码位于此处
// Code for generating barcodes goes here
}
```

## 步骤 3:配置条形码属性
`BarcodeGenerator` 是创建和渲染条码符号的主要类。

## 步骤 3:配置条码属性

您可以自定义 DataMatrix 条形码的各种属性,例如尺寸和 ECC(纠错码)类型。以下是将 X 尺寸设置为 4 像素并选择 ECC200 的示例
您可以自定义 DataMatrix 条码的各种属性,例如尺寸和 ECC(错误纠正码)类型。以下示例将 X 维度设置为 4 像素并选择 ECC200:

```csharp
generator.Parameters.Barcode.XDimension.Pixels = 4;
generator.Parameters.Barcode.DataMatrix.DataMatrixEcc = DataMatrixEccType.Ecc200;
```

## 第4步:设置DataMatrix版本并保存
`XDimension` 设置每个模块的像素大小,`DataMatrixEcc` 选择错误纠正级别。

您可以通过设置行数和列数来指定 DataMatrix 版本。配置版本后,保存条形码图像。
## 步骤 4:设置 DataMatrix 版本并保存

例如,要使用 ECC200 创建 22 行 22 列的 DataMatrix 条形码:
通过设置行数和列数来指定 DataMatrix 版本。配置完版本后,保存条码图像。

例如,使用 ECC200 创建 22 行 22 列的 DataMatrix 条码:

```csharp
generator.Parameters.Barcode.DataMatrix.DataMatrixVersion = DataMatrixVersion.ECC200_22x22;
generator.Save($"{path}DataMatrixRows22Columns22Ecc200.png", BarCodeImageFormat.Png);
```

同样,您可以根据需要更改版本和ECC类型来生成具有不同参数的条码
同理,您可以通过更改版本和 ECC 类型生成不同参数的条码

## 步骤 5:对其他版本重复此操作
## 步骤 5:为其他版本重复操作

对于其他 DataMatrix 版本,您可以重复步骤 4。例如,要使用 ECC200 创建 12 行 64 列的条形码
您可以对其他 DataMatrix 版本重复步骤 4。例如,使用 ECC200 创建 12 行 64 列的条码

```csharp
generator.Parameters.Barcode.DataMatrix.DataMatrixVersion = DataMatrixVersion.DMRE_12x64;
Expand All @@ -90,53 +153,64 @@ generator.Save($"{path}DataMatrixRows12Columns64Ecc200.png", BarCodeImageFormat.

## 步骤 6:切换 ECC 类型

如果要将 ECC 类型更改为 Ecc140,可以通过更新 ECC 属性来实现
如果想将 ECC 类型改为 Ecc140,只需更新 ECC 属性

```csharp
generator.Parameters.Barcode.DataMatrix.DataMatrixEcc = DataMatrixEccType.Ecc140;
```

## 步骤 7:生成不同版本和 ECC 的条形码
## 步骤 7:使用不同版本和 ECC 生成条码

对其他 DataMatrix 版本和 ECC 类型重复步骤 4,用唯一的文件名保存每个条形码
对其他 DataMatrix 版本和 ECC 类型重复步骤 4,并为每个条码使用唯一文件名保存

```csharp
generator.Parameters.Barcode.DataMatrix.DataMatrixVersion = DataMatrixVersion.ECC000_140_29x29;
generator.Save($"{path}DataMatrixRows29Columns29Ecc140.png", BarCodeImageFormat.Png);
```

现在您已经了解了如何使用 Aspose.BarCode for .NET 生成 DataMatrix 条形码,您可以轻松地将此功能集成到您的 .NET 应用程序中。
现在您已经学会如何使用 Aspose.BarCode for .NET 生成 DataMatrix 条码,能够轻松将此功能集成到 .NET 应用程序中。

## 常见问题与排查技巧

## 结论
- **版本尺寸不正确** – DataMatrix 版本拥有固定的行/列配对。提供不匹配的配对(例如 10 × 20)会抛出 `ArgumentException`。请始终使用 API 文档中列出的受支持组合。
- **缺少许可证** – 试用模式下生成的图像会带有水印。使用 `License license = new License(); license.SetLicense("Aspose.BarCode.lic");` 在创建生成器之前加载有效许可证,以去除水印。`License` 类用于加载许可证文件并激活产品。
- **图像尺寸过大** – 若需高分辨率输出,可增大 `XDimension` 属性;库会按比例缩放图像而不失去可读性。

Aspose.BarCode for .NET 简化了在 .NET 应用程序中生成 DataMatrix 条形码的过程。通过此分步指南,您可以创建具有不同版本和 ECC 类型的条形码,从而提供灵活性和自定义来满足您的特定需求。
## 常见问答

如果您有任何疑问或需要帮助,请随时访问[Aspose.BarCode for .NET 文档](https://reference.aspose.com/barcode/net/)或查看[Aspose.BarCode 论坛](https://forum.aspose.com/c/barcode/13)为了支持。
**问:DataMatrix 条码中的 ECC 是什么?**
答:ECC(错误纠正码)添加冗余数据,使扫描仪即使在符号部分受损或脏污时也能恢复原始信息。

## 常见问题解答
**问:我可以使用 Aspose.BarCode for .NET 自定义 DataMatrix 条码的尺寸吗?**
答:可以,正如教程所示,您可以通过设置行数和列数来自定义 DataMatrix 条码的尺寸。

### Q1:DataMatrix 条码中的 ECC 是什么?
**问:在哪里可以下载 Aspose.BarCode for .NET?**
答:您可以从 **Aspose.BarCode .NET 下载页面** 下载: [Aspose.BarCode .NET 下载页面](https://releases.aspose.com/barcode/net/)。

A1:ECC(纠错码)是 DataMatrix 条码的重要组成部分,有助于确保数据完整性。不同的 ECC 级别提供不同程度的纠错。
**问:Aspose.BarCode for .NET 有免费试用吗?**
答:有,您可以在此获取免费试用: [这里](https://releases.aspose.com/barcode/net/)。

### 问题 2:我可以使用 Aspose.BarCode for .NET 生成具有自定义尺寸的 DataMatrix 条形码吗?
**问:如何获取 Aspose.BarCode for .NET 的临时许可证?**
答:访问临时许可证页面获取临时许可证: [temporary license page](https://purchase.aspose.com/temporary-license/)。您也可以在此浏览完整的发布目录: [here](https://releases.aspose.com/)。

A2:是的,您可以通过设置行数和列数来自定义 DataMatrix 条形码的尺寸,如教程中所示
如有任何疑问或需要帮助,请访问 [Aspose.BarCode for .NET 文档](https://reference.aspose.com/barcode/net/) 或查看 [Aspose.BarCode 论坛](https://forum.aspose.com/c/barcode/13) 获取支持

### Q3:哪里可以下载 Aspose.BarCode for .NET?
---

A3:您可以从以下位置下载 Aspose.BarCode for .NET[这个链接](https://releases.aspose.com/barcode/net/).
**最后更新:** 2026-08-22
**测试环境:** Aspose.BarCode 24.11 for .NET
**作者:** Aspose

### Q4:Aspose.BarCode for .NET 有免费试用版吗?
## 相关教程

A4:是的,您可以免费试用 Aspose.BarCode for .NET[这里](https://releases.aspose.com/).
- [How to Generate DataMatrix Barcodes (ECC 200) with Aspose.BarCode for .NET](/barcode/net/datamatrix-barcode-configuration/datamatrix-ecc-200-configuration/)
- [How to Generate DataMatrix ECC 000-140 Barcodes with Aspose.BarCode for .NET](/barcode/net/datamatrix-barcode-configuration/datamatrix-ecc-000-140-configuration/)
- [How to Read DataMatrix Barcodes with Aspose.BarCode for .NET](/barcode/net/datamatrix-barcode-reading/)

### Q5:如何获得 Aspose.BarCode for .NET 的临时许可证?

A5:要获取 Aspose.BarCode for .NET 的临时许可证,请访问[这个链接](https://purchase.aspose.com/temporary-license/).
{{< /blocks/products/pf/tutorial-page-section >}}

{{< /blocks/products/pf/main-container >}}
{{< /blocks/products/pf/main-wrap-class >}}

{{< blocks/products/products-backtop-button >}}
{{< blocks/products/products-backtop-button >}}
Loading