The invention relates to the technical field of two-dimensional
code generation, and discloses a multi-thread two-dimensional
code generation algorithm based on Web Workers. The multi-thread two-dimensional
code generation algorithm comprises the following steps that: a browser end receives a two-dimensional code generation request, and acquires two-dimensional code generation data according to the two-dimensional code generation request; encoding the two-dimensional code generation data, and taking the encoded data as two-dimensional code content information parameters; packaging the two-dimensional code content information parameter and a preset two-dimensional code parameter into a parameter object by usinga
JavaScript main thread of the browser, and instantiating a Worker sub-thread; sending the parameter object in the
JavaScript main thread to the Worker sub-thread; analyzing the received parameter object and calculating a corresponding two-dimensional code matrix by the Worker sub-thread; traversing the two-dimensional code matrix by the Worker sub-thread, and rendering the two-dimensional code by using a (rect)
label of the SVG to obtain an SVG image of the two-dimensional code; and the Worker sub-thread sends the SVG image back to the
JavaScript main thread, and the JavaScript main thread directly displays the two-dimensional code on an
HTML page in an inline SVG mode.the multi-thread two-dimensional code generation
algorithm improves the generation efficiency of the two-dimensional code.