产品类库

当前位置:首页>产品类库

Barcode 条码二维码组件

时间:2026-03-18 访问量:0

一、类库简介

`loquat.barcode` 是一个功能完整的条码生成和解析 COM 对象,支持多种一维和二维条码格式,专为 VBA/VB6 设计。

二、类库特征

## 🎨 支持的条码类型

### 一维条码 (1D)

- Code 128

- Code 39

- Code 93

- EAN-8 / EAN-13

- UPC-A / UPC-E

- ITF (Interleaved 2 of 5)

- ITF-14

- Codabar

- MSI Plessey

- DataBar (RSS)

### 二维条码 (2D)

- QR Code

- Data Matrix

- PDF417

- Aztec Code

- MaxiCode

## 🔧 特效选项详细说明

 条码特效文档

三、使用简介

Dim barcode As Object
Set barcode = CreateObject("loquat.barcode")

' 生成条码
Dim result As String
result = barcode.Generate("QRCode", "Hello World", "{""width"":200,""height"":200}")

' 解析条码
result = barcode.Decode(imageBase64, "{""try_harder"":true}")

四、详细说明

 1、生成条码

 Generate - 生成条码图像

 result = barcode.Generate(barcodeType, content, options)

**参数**:

- `barcodeType` (BSTR): 条码类型

 - 一维:`"Code128"`, `"Code39"`, `"EAN13"`, `"UPC-A"`, `"ITF"`, `"Codabar"`, `"Code93"` 等

 - 二维:`"QRCode"`, `"DataMatrix"`, `"PDF417"`, `"Aztec"` 等

- `content` (BSTR): 条码内容

- `options` (BSTR, 可选): JSON 选项字符串,默认 `"{}"`

**返回值** (JSON):

```json

{

 "success": true,

 "data": {

 "image_base64": "iVBORw0KGgo...",

 "format": "PNG",

 "width": 200,

 "height": 200,

 "mime_type": "image/png"

 },

 "error": ""

}

```

**选项参数** (options JSON):

```json

{

 "width": 200, // 宽度(像素),0=自动

 "height": 200, // 高度(像素),0=自动

 "scale": 1.0, // 缩放比例

 "margin": 10, // 边距(像素)

 "foreground_color": "#000000", // 前景色

 "background_color": "#FFFFFF", // 背景色

 "transparent": false, // 透明背景

 "show_text": true, // 显示文本

 "text_position": "bottom", // 文本位置

 "format": "PNG", // 输出格式: "PNG", "JPEG", "SVG"

 "error_correction": "H", // 错误纠正级别(仅 QR Code): "L", "M", "Q", "H"

 "gradient_type": "linear", // 渐变类型: "none", "linear", "radial", "rainbow"

 "gradient_colors": ["#FF0000", "#0000FF"], // 渐变颜色

 "logo_path": "C:\\\\\\\\logo.png", // Logo 路径(仅二维码)

 "logo_size": 0.2, // Logo 大小比例(0.0-0.4)

 "module_shape": "square", // 模块形状: "square", "circle", "rounded", "diamond"

 "shadow_enabled": false, // 启用阴影

 "shadow_offset_x": 3, // 阴影 X 偏移

 "shadow_offset_y": 3, // 阴影 Y 偏移

 "shadow_color": "#00000080" // 阴影颜色(支持透明度)

}

```

 GenerateToFile - 生成条码文件

result = barcode.GenerateToFile(barcodeType, content, filePath, options)

**参数**:

- `barcodeType` (BSTR): 条码类型

- `content` (BSTR): 条码内容

- `filePath` (BSTR): 输出文件路径

- `options` (BSTR, 可选): JSON 选项字符串

**返回值** (JSON):

```json

{

 "success": true,

 "data": {

 "file_path": "C:\\\\\\\\output.png",

 "format": "PNG",

 "width": 200,

 "height": 200

 },

 "error": ""

}

```

 2、解析条码

 Decode - 从Base64图像解码条码

result = barcode.Decode(imageBase64, options)

**参数**:

- `imageBase64` (BSTR): Base64 编码的图像数据

- `options` (BSTR, 可选): JSON 选项字符串

**返回值** (JSON):

```json

{

 "success": true,

 "data": {

 "barcodes": [

 {

 "type": "QRCode",

 "content": "Hello World",

 "format": "QR_CODE",

 "points": [[10, 10], [200, 10], [200, 200], [10, 200]],

 "confidence": 1.0

 }

 ],

 "count": 1

 },

 "error": ""

}

```

**选项参数** (options JSON):

```json

{

 "try_harder": true, // 更努力尝试(更慢但更准确)

 "multiple": false, // 是否查找多个条码

 "formats": [], // 指定格式(空数组=全部)

 "contrast": 1.0, // 对比度调整(1.0=原始)

 "brightness": 1.0, // 亮度调整(1.0=原始)

 "rotation": 0, // 旋转角度(0, 90, 180, 270)

 "auto_rotate": false, // 自动旋转

 "grayscale": false, // 转灰度

 "invert": false, // 反转颜色

 "region": { // 扫描区域限制(可选)

 "x": 0,

 "y": 0,

 "width": 100,

 "height": 100

 }

}

```

 DecodeFromFile - 从文件解码条码

result = barcode.DecodeFromFile(filePath, options)

 DecodeFromBytes - 从字节数组解码条码

result = barcode.DecodeFromBytes(imageData, options)

 3、辅助方法

 GetSupportedTypes - 获取支持的条码类型列表

result = barcode.GetSupportedTypes("all") ' 或 "1d", "2d", "generate", "decode"

**返回值** (JSON):

```json

{

 "success": true,

 "data": {

 "types": [

 {

 "name": "QRCode",

 "display_name": "QR Code",

 "category": "2d",

 "can_generate": true,

 "can_decode": true,

 "max_length": 2953,

 "min_length": 1

 }

 ]

 },

 "error": ""

}

```

 ValidateContent - 验证条码内容

result = barcode.ValidateContent("EAN13", "1234567890123")

**返回值** (JSON):

```json

{

 "success": true,

 "data": {

 "valid": true,

 "error": ""

 },

 "error": ""

}

 SetDebug - 设置调试模式

barcode.SetDebug True ' 或 False

 SetDebugLogPath - 设置调试日志文件路径

result = barcode.SetDebugLogPath("C:\\\\temp\\\\barcode_debug.log")

 GetSystemFonts - 获取系统字体列表

result = barcode.GetSystemFonts()

 SetSIMDEnabled - 设置 SIMD 优化开关

barcode.SetSIMDEnabled True ' 需要 CPU 支持 AVX2

 GetSIMDStatus - 获取 SIMD 状态信息

result = barcode.GetSIMDStatus()

**返回值** (JSON):

```json

{

 "success": true,

 "data": {

 "enabled": true,

 "cpu_has_avx2": true,

 "active": true

 },

 "error": ""

}

```

 4、批量操作

 BatchGenerate - 批量生成条码

Dim requests As String

requests = "[{""type"":""QRCode"",""content"":""Content1"",""options"":{}},{""type"":""Code128"",""content"":""Content2"",""options"":{}}]"

result = barcode.BatchGenerate(requests)

**返回值** (JSON):

```json

{

 "success": true,

 "data": {

 "results": [

 {"success": true, "image_base64": "...", "index": 0},

 {"success": false, "error": "...", "index": 1}

 ]

 },

 "error": ""

}

```

 BatchDecode - 批量解码条码

Dim images As String

images = "[{""image_base64"":""..."",""options"":{}},{""file_path"":""C:\\\\\\\\test.png"",""options"":{}}]"

result = barcode.BatchDecode(images)

五、下载地址

 统一下载地址


上一页:EventApp后期绑定事件触发

下一页:ProxyServer(Windows端32/64跨位数调用DLL代理组件)

发表评论:

评论记录

暂无数据!