How to create an artistic QR barcode?
In This Topic
QR code symbology supports error correction algorithm with 4 levels for damaged barcode data recovery:
| Error Correction Level |
Recovery Capacity %(approx.) |
| L |
7% |
| M |
15% |
| Q |
25% |
| H |
30% |
The ability to recover the barcode value allows to create artistic QR barcodes, i.e. draw a small image over a barcode region.
Important! Artistic QR barcode is a "distorted" QR barcode and it has lower recovering capacity than the common one.
The algorithm below shows how to create an artistic QR barcode with recovery capacity reduced not more than 2 times.
The algorithm for creation of artistic QR barcode
Terms used in algorithm:
- Logo image - image to draw on the barcode
- Cell - cell of the barcode, can be black or white
-
Cell size - size of the "cell", can be got/set with the WriterSettings.MinWidth property
-
Cell area - area of the "cell", "cell_area" = "cell_size" * "cell_size"
- Version of QR barcode - version of QR barcode, can be got/set with the WriterSettings.QRSymbol property
- Recovery capacity - recovery capacity in percents, see the table above
- Assurance factor - assurance factor, available values from 0 to 1, recommended value is 0.2
Steps of algorithm:
-
Calculate the area, in "cells" ^2, for the "logo image":
"logo_image_area_in_cells" = logo_image_width_in_pixels * logo_image_height_in_pixels / cell_area_in_pixels
-
Generate a common QR barcode with necessary data and error correction level (error correction level "H" is recommended).
Get the "version of generated QR barcode":
"qr_version" = value of the WriterSettings.QRSymbol property
-
Calculate the width/height, in "cells", of the generated QR barcode:
"qr_barcode_width_in_cells" = 21 + (qr_version - 1) * 4
-
Calculate the area, in "cells" ^2, of the QR barcode which cannot be used for the logo image:
"system_qr_barcode_area_in_cells" = 9 ^ 2 * 3 = 243
-
Calculate the area, in "cells" ^2, of the QR barcode which can be used for the logo image:
"available_qr_barcode_area_for_logo_image_in_cells" = qr_barcode_width_in_cells ^ 2 - system_qr_barcode_area_in_cells
-
Calculate the area, in "cells" ^2, of the QR barcode which can be used for the logo image, the recovery capacity of QR barcode will not be reduced more than 2 times:
"safe_qr_barcode_area_for_logo_image_in_cells" = available_qr_barcode_area_for_logo_image_in_cells * ("recovery_capacity" / 100) * (1 - "assurance_factor") * 0.5
-
Increment the "qr_version" and go to step 3 if "logo_image_area_in_cells" is less than "safe_qr_barcode_area_for_logo_image_in_cells"
-
Draw the logo image on the barcode image in the green or yellow area (see image below)
-
Read the generated QR barcode using the barcode reader and get the reading quality of barcode:
"reading_quality" = value of the IBarcodeInfo.ReadingQuality property
-
Increment the "qr_version" and go to step 3 if "reading_quality" is less than 0.5
- Artistic QR barcode is generated
Here is an example that shows how to create an artistic QR barcode with cell size 5x5 pixels and logo image with size 112x65 pixels:
-
"logo_image_area_in_cells" = 112 * 65 / (5 * 5) = 292
-
Barcode text: https://www.vintasoft.com
Error correction level: H
"qr_version" = 3
-
"qr_barcode_width_in_cells" = 21 + (3 - 1) * 4 = 29
-
"available_qr_barcode_area_for_logo_image_in_cells" = 29 ^ 2 - 243 = 598
-
"safe_qr_barcode_area_for_logo_image_in_cells" = 598 * (30 / 100) * (1 - 0.2) * 0.5 = 71
-
292 > 71, "qr_version" = 9 AND go to step 3 of the main algorithm
-
"qr_barcode_width_in_cells" = 21 + (9 - 1) * 4 = 53
-
"available_qr_barcode_area_for_logo_image_in_cells" = 49 ^ 2 - 243 = 2566
-
"safe_qr_barcode_area_for_logo_image_in_cells" = 2566 * (30 / 100) * (1 - 0.2) * 0.5 = 307
-
292 < 307, go to step 8 of the main algorithm
-
Draw the logo image on the barcode image in the green or yellow area (see image below)
-
"reading_quality" = 0.66
-
Artistic QR barcode is generated