Skip to main content

技术指南 · ISO/IEC 18004

QR 码如何生成?完整编码流程详解

QR 码生成是对 ISO/IEC 18004 编码的正向应用:在任何人扫描之前,它会将 URL、文本或数据载荷转换为方形模块矩阵。本 2026 指南仅介绍符号生成流程,从数据模式选择到最终导出。

QR 码如何生成?

QR 码通过将输入数据编码为比特流、添加 Reed-Solomon 纠错码字、把比特映射到方形模块矩阵、应用最佳掩码模式,并插入格式和版本信息以及必需的静区来生成。合规的 QR 生成器会自动执行这套 ISO/IEC 18004 流程,生成可扫描的黑白符号。

生成 QR 码是什么意思?

生成 QR 码是指创建存储数据载荷的符号;这不同于对该符号进行解码的扫描,也不同于符号创建后发生的动态重定向管理。

A QR code is a two-dimensional barcode symbology. Its black and white squares are modules, and their arrangement carries both payload data and the instructions a scanner needs to interpret it.

A QR generator analyzes input and applies the ISO/IEC 18004 rules for capacity, structure, and error correction. A scanner performs the reverse operation; for that decoding flow, see how QR codes work.

A static QR code stores its final payload in the symbol. A dynamic QR code stores a redirect URL in the same kind of symbol, while its editable destination and later analytics live outside the encoding process.

QR 码生成流程是什么?

QR 码生成过程包含十个确定性阶段:输入分析、编码、纠错、消息结构化、矩阵构建、比特放置、掩码选择、格式/版本信息插入、静区添加和导出。

以下流程适合用来评估 QR 库,或理解生成器处理 URL 时所做的工作。

  1. 1

    Analyze input and choose a data mode

    The generator selects numeric, alphanumeric, byte, or Kanji encoding from the characters in the payload.

  2. 2

    Encode data into codewords

    Mode and character-count indicators, payload bits, a terminator, and padding are formed into eight-bit codewords.

  3. 3

    Generate error correction

    Reed-Solomon arithmetic creates redundant codewords for the selected recovery level.

  4. 4

    Structure the final message

    Data and error-correction blocks are interleaved in the order required by the selected version and level.

  5. 5

    Construct the matrix

    The generator chooses a QR version and reserves finder, timing, alignment, and information areas.

  6. 6

    Place data bits

    Codeword bits travel through remaining modules in a vertical zigzag pattern, with remainder bits where required.

  7. 7

    Evaluate mask patterns

    All eight XOR masks are scored to avoid patterns that are difficult for cameras to distinguish.

  8. 8

    Insert format and version information

    The chosen error-correction level and mask are BCH-protected; versions 7 and above also receive version information.

  9. 9

    Add the quiet zone

    A clear border at least four modules wide separates the symbol from neighboring artwork.

  10. 10

    Export and validate

    The finished matrix can be rendered as PNG, SVG, PDF, or EPS and tested at its intended print size.

查看流程后免费创建 QR 码

第 1 步:生成器如何选择 QR 码数据模式?

应按字符集而非载荷类型名称选择数据模式。数字数据压缩最紧凑;URL 和 WiFi 字符串通常含有小写字母和标点,因此一般需要字节模式。

A data mode is the rule set used to convert characters into bits. A URL such as https://example.com commonly uses byte mode; a WiFi payload string also commonly uses byte mode, but has a different payload structure. See types of QR codes for format-selection guidance.

模式字符集最适合
Numeric0–9Phone numbers, numeric IDs, and digits-only payloads
Alphanumeric0–9, A–Z, space, $ % * + - . / :Uppercase coupon codes and simple identifiers
ByteISO 8859-1 or arbitrary byte sequencesURLs, email, WiFi strings, mixed-case and UTF-8 text
KanjiShift JIS double-byte charactersEligible Japanese text
浏览 QR 码类型

Step 2: How is data encoded into codewords?

Encoding converts the selected mode, character count, and payload into bits, then adds a terminator and pad bytes until the selected version's data capacity is filled.

A codeword is an eight-bit unit of either encoded payload data or error-correction information. The mode indicator tells the decoder how to read the following bits, and the character-count indicator tells it how much data follows.

Payload length and error-correction level determine the smallest QR version with enough capacity. A longer URL or a higher recovery level can therefore increase the module count even when the visible design is unchanged.

Step 4: How is the QR matrix built?

A QR matrix is the square grid of modules that holds fixed patterns, data modules, and error-correction modules. Version 1 contains 21×21 modules, and each higher version adds four modules per side.

Finder patterns are the three 7×7 corner markers that help a scanner locate and orient the code. Timing patterns synchronize the module grid, while alignment patterns improve geometric correction on larger versions.

The generator reserves areas for format information and, from Version 7 onward, version information before placing data. Version 40 reaches 177×177 modules.

Step 5: How are codewords placed in modules?

After fixed patterns are reserved, the generator places data and error-correction bits in paired columns that zigzag from the lower-right toward the upper-left of the matrix.

Each bit becomes one light or dark module after masking. Reserved function modules are skipped, and remainder bits fill any capacity that is not represented by a full codeword.

This placement rule is why a QR symbol is a structured matrix rather than a visual hash: every position has a prescribed role.

Step 6: What are QR code mask patterns?

Mask patterns are eight XOR templates applied to data modules to break up large uniform regions and repeated patterns that can make camera detection less reliable.

The generator evaluates all eight masks and assigns penalty points for undesirable runs, blocks, and balance. It uses the lowest-penalty result and records the selected mask in format information.

Masking changes the visual distribution of modules, not the underlying payload. The scanner reads the mask identifier and reverses the operation during decoding.

Step 7: What are format and version information?

Format information tells a scanner the error-correction level and selected mask; version information identifies versions 7 through 40. Both use BCH protection for reliable reading.

Format information is duplicated near the finder patterns because it is needed early in decoding. Version information is placed in reserved areas on larger symbols.

These fields are part of symbol generation, so a code that merely resembles a QR image is not necessarily a valid QR symbol.

Step 8: Why does the quiet zone matter in final output?

The quiet zone is a mandatory clear border of at least four modules on every side. It lets scanners distinguish finder patterns from surrounding text, artwork, and borders.

PNG is useful for fixed pixel output, while SVG, PDF, and EPS preserve vector edges for large-format printing. Raster scaling can blur individual modules, so print resolution must preserve a readable module size.

Use the QR code size guide for physical sizing rules; generation creates the symbol, while production choices determine how faithfully it is reproduced.

Static vs dynamic QR codes in the generation context

Both static and dynamic QR codes start with a generated symbol. A static symbol encodes its final payload, while a dynamic symbol encodes a redirect URL whose destination can be edited later.

The entity chain is encoding → symbol → optional redirect layer → editable URL → scan analytics. Analytics attach when a dynamic redirect is requested, not while the QR matrix is generated.

Read about static vs dynamic QR codes for the business decision, and see plans for dynamic features without assuming every generator exposes low-level version or mask controls.

What happens in a typical QR generator, including QR-Build?

A typical generator automates ISO/IEC 18004 encoding, then renders the finished symbol in the requested format. Design overlays such as color and logo treatments are applied after core symbol generation and must preserve contrast and capacity.

At QR-Build, we treat output validation as a production step: we review core symbol output and use cross-device scan tests on iPhone and Android before export. Compliant generators follow ISO/IEC 18004; implementation details and available controls vary, so verify them in vendor documentation.

Open-source libraries such as ZXing and qrcode.js implement the same core pipeline. Teams needing API-level evaluation can review our QR code generator for developers.

QR code generation vs QR code scanning

Generation encodes forward from data to modules; scanning decodes backward from modules to data. This page covers the forward pipeline only.

Understanding generation helps explain why quiet zones, module size, contrast, and error correction affect reliability. For the camera-detection and decoding sequence, read how QR codes work.

第 3 步:什么是 Reed-Solomon 纠错?

Reed-Solomon 是 QR 符号使用的分组纠错码。它会在矩阵放置前增加冗余码字,使扫描器在部分模块损坏或被遮挡时仍能恢复数据。

The percentages below are approximate recovery capacities commonly associated with each level; real results depend on where and how damage occurs. Higher correction reduces available data capacity for a given version and can require a larger symbol.

级别大致恢复能力典型用途
L~7%Clean digital displays with low damage risk
M~15%Common general-purpose default; confirm a generator's setting
Q~25%Outdoor placement or moderate wear
H~30%Logo overlays, heavy print, or harsher environments
阅读 QR 码纠错指南

数据模式和纠错选择框架

根据允许的字符选择数据模式,根据物理风险和设计处理选择纠错级别。如果它迫使最终印刷中的模块过小,更高级别并不一定更好。
情况数据模式EC 级别输出提示
Phone number onlyNumericMUse SVG for print
Uppercase coupon codeAlphanumericMTest contrast
URL or WiFi stringByteM; H with a logoPreserve quiet zone
Logo overlayUsually byteHIncrease final print size
Outdoor signUsually byteQ or HCheck the size guide
Campaign with URL changesByte + dynamic redirectMUse a redirect layer and scan analytics

QR 码生成中的常见错误

大多数扫描失败源自围绕正确生成符号的制作选择:裁掉静区、对比度不足、模块太小,或恢复级别不适合设计。

Cropping the quiet zone

Do not place a border, text, or artwork inside the required clear margin.

Using too little error correction for a logo

A logo obscures modules; compensate deliberately and test the final artwork.

Forcing the wrong character encoding

Mixed-case text and non-ASCII content often need byte-aware handling rather than an alphanumeric assumption.

Reducing contrast

Decorative colors can make module boundaries difficult for cameras to separate.

Shrinking a raster file too far

Blurred or merged pixels can destroy module geometry even when the source matrix was valid.

Trusting a QR-like image

A square pattern must include valid structure, information fields, and quiet zone to be spec-compliant.

可靠生成 QR 码的最佳实践

使用符合规范的生成器,保留四模块静区,使纠错级别匹配物理条件,并在批量生产前用多个设备测试最终导出文件。

Start with ISO/IEC 18004 output

Use a generator or library that documents standards-based QR encoding.

Match recovery to the environment

Factor in print wear, logo coverage, lighting, and expected viewing distance.

Keep the quiet zone intact

Treat the white border as part of the symbol, not as optional surrounding whitespace.

Test iOS and Android

Test the final printed or displayed asset, not only the source file on one screen.

Choose vector for large print

SVG, PDF, or EPS help preserve crisp module edges at larger dimensions.

Use dynamic QR codes for changing campaigns

An editable redirect destination avoids re-encoding when a campaign URL changes; scan analytics occur on that redirect layer.

术语表:QR 码生成术语

这些定义描述了同一过程的关联部分:数据模式创建码字,码字成为模块,模块构成受 ISO/IEC 18004 规范约束的 QR 符号。

Module

One black or white square cell in a QR matrix.

Codeword

An eight-bit unit of encoded data or error-correction information.

Data mode

The character-encoding scheme selected before payload bits are created.

Error correction level

The L, M, Q, or H setting that controls redundant Reed-Solomon codewords.

Mask pattern

One of eight XOR templates used to improve module distribution.

Quiet zone

The required clear border of at least four modules around a QR symbol.

Finder pattern

One of the three large corner patterns that supports detection and orientation.

Alignment pattern

A smaller reference pattern that helps correct distortion in larger versions.

Timing pattern

Alternating modules that help synchronize the scanner to the grid.

Version

The QR size tier; Version 1 is 21×21 modules and each step adds four modules per side.

Format information

BCH-protected data identifying the error-correction level and selected mask.

Reed-Solomon

The error-correction algorithm that adds recoverable redundancy to QR codewords.

Static QR code

A symbol whose encoded payload remains fixed after creation.

Dynamic QR code

A symbol that encodes a redirect URL while its destination remains editable behind that redirect.

Related QR code resources

常见问题

这些回答涉及 QR 码符号的生成,而非单独的扫描教程或 QR 格式分类。

How are QR codes generated?

QR codes are generated by encoding input into bits, adding Reed-Solomon error correction codewords, placing data in a module matrix, applying a mask, inserting format and version information, and adding a quiet zone under ISO/IEC 18004.

What algorithm is used to generate QR codes?

QR generation follows ISO/IEC 18004. Its core algorithm includes data-mode selection, bit encoding, Reed-Solomon error correction, zigzag matrix placement, mask scoring, and format-information insertion.

How does a QR code generator turn a URL into a QR code?

A generator typically encodes an https URL in byte mode, selects a version from data length and error-correction level, constructs the module matrix, selects a mask, and exports the finished symbol.

What are QR code data modes?

Numeric, alphanumeric, byte, and Kanji modes define how characters convert to bits. Numeric is compact for digits, while byte mode handles URLs, mixed-case text, and arbitrary byte data.

When should I use byte mode versus alphanumeric mode?

Use byte mode for URLs, lowercase text, and special characters. Use alphanumeric mode only when the payload stays within its uppercase letters, digits, space, and limited-symbol set.

What is Reed-Solomon error correction in QR codes?

Reed-Solomon adds redundant codewords so a scanner can recover data when modules are damaged. Increasing from L through H generally increases recovery capacity while reducing data capacity for a version.

What are QR code mask patterns?

Eight mask patterns XOR with data modules to prevent large uniform regions and repeated structures. The generator scores each result and selects the lowest-penalty mask.

How many modules are in a QR code?

Module count depends on version. Version 1 is 21×21 modules, each version adds four modules per side, and Version 40 is 177×177 modules.

How is QR code version determined?

A generator selects the smallest version that fits the payload under the chosen data mode and error-correction level. More data or higher recovery requires more capacity.

Does generating a QR code require an internet connection?

No. Generation is local computation. Internet is only needed to use a cloud service or to access content at a URL encoded in the finished symbol.

What is the difference between generating and printing a QR code?

Generation creates a digital symbol; printing reproduces it on a physical surface. Final scan reliability depends on contrast, module size, quiet-zone preservation, and print quality.

Can I change a QR code after it is generated?

A static QR code has fixed encoded data. A dynamic QR code can keep its symbol while changing the destination behind its redirect URL; visual changes still require a safe re-export.

What is a quiet zone and why does it matter?

The quiet zone is a clear border of at least four modules around a QR symbol. Cropping it can prevent scanners from finding the symbol reliably.

What happens when you click Generate in QR-Build?

QR-Build processes the supplied content through the QR encoding pipeline, applies optional design treatments, and exports a scannable symbol. Dynamic QR workflows also register a redirect URL for later editing and analytics.

准备好将数据转换为 QR 码了吗?

使用 QR-Build 创建基于标准的 QR 符号,然后在用户实际扫描的环境中进行验证。

使用 QR-Build 创建 QR 码
QR Code - QR-Build

创建您的 QR 码

创建 QR 码