Engineer Blog – About QR Code Generation

Welcome to our engineer blog, where we share our ongoing learning experiences. This post is part of Unit 0, which focuses on web design. Today, I’d like to introduce an opportunity I had to work with something less commonly encountered: QR code generation.

Preparation

For this implementation, I used Java. Since my development environment is Gradle-based, adding the necessary libraries was as simple as including the following in the build.gradle file. (Isn’t it convenient how accessible things have become these days?)

Reference Site:
Getting Started Developing · zxing/zxing Wiki · GitHub

The library used here is ZXing, an open-source Java library that enables the creation and reading of one-dimensional codes (such as barcodes) and two-dimensional codes (like QR codes).

Implementation

The key element for generating QR codes is the encode method of the QRCodeWriter class. As summarized in the comments, the following parameters can be specified:

  1. First parameter: The content to be displayed.
  2. Second parameter: The output format ( BarcodeFormat from the ZXing 3.5.3 API).
  3. Third parameter: The dimensions.

The generated data is stored in a variable of type BitMatrix (bm). By specifying the output format in the writeToStream method, you can save the generated QR code in your desired format. In this case, we output the QR code in PNG format.

While the actual implementation involves handling API requests and returning the output result to the screen, I’ll omit those details here.

Summary

Nowadays, if you just want to generate a QR code once for testing purposes, there’s no need to write a program from scratch. You can find many online QR code generators with just a quick search. Some even let you customize the design or offer formats tailored to specific use cases, making them surprisingly fun to explore.

This post covered only the basics, but I hope it gave you an idea of how QR code generation works. If you found this interesting, I’d be delighted.

Stay tuned for the next engineer blog post!

P.S. The content of the QR code includes a closing message!