{"id":5765,"date":"2025-01-22T10:10:39","date_gmt":"2025-01-22T01:10:39","guid":{"rendered":"https:\/\/dandelions.co.jp\/blog\/?p=5765"},"modified":"2025-01-22T10:10:39","modified_gmt":"2025-01-22T01:10:39","slug":"engineer-blog-about-qr-code-generation","status":"publish","type":"post","link":"http:\/\/dandelions.co.jp\/blog\/blog\/2025\/01\/22\/engineer-blog-about-qr-code-generation\/","title":{"rendered":"<strong>Engineer Blog \u2013 About QR Code Generation<\/strong>"},"content":{"rendered":"\n<p>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\u2019d like to introduce an opportunity I had to work with something less commonly encountered: QR code generation.<\/p>\n\n\n\n<h3>Preparation<\/h3>\n\n\n\n<p>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 <code>build.gradle<\/code> file. (Isn&#8217;t it convenient how accessible things have become these days?)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"757\" height=\"123\" src=\"http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/jyunbi.png\" alt=\"\" class=\"wp-image-5720\" srcset=\"http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/jyunbi.png 757w, http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/jyunbi-300x49.png 300w\" sizes=\"(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/figure>\n\n\n\n<p><strong>Reference Site:<\/strong><br><a href=\"https:\/\/github.com\/zxing\/zxing\/wiki\">Getting Started Developing \u00b7 zxing\/zxing Wiki \u00b7 GitHub<\/a><\/p>\n\n\n\n<p>The library used here is <strong>ZXing<\/strong>, 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).<\/p>\n\n\n\n<h3>Implementation<\/h3>\n\n\n\n<p>The key element for generating QR codes is the <code>encode<\/code> method of the <code>QRCodeWriter<\/code> class. As summarized in the comments, the following parameters can be specified:<\/p>\n\n\n\n<ol><li><strong>First parameter:<\/strong> The content to be displayed.<\/li><li><strong>Second parameter:<\/strong> The output format ( <a rel=\"noreferrer noopener\" href=\"https:\/\/zxing.github.io\/zxing\/apidocs\/com\/google\/zxing\/BarcodeFormat.html\" target=\"_blank\"><code>BarcodeFormat<\/code> from the ZXing 3.5.3 API<\/a>).<\/li><li><strong>Third parameter:<\/strong> The dimensions.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"231\" src=\"http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/\u30bd\u30fc\u30b9png-1-1024x231.png\" alt=\"\" class=\"wp-image-5741\" srcset=\"http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/\u30bd\u30fc\u30b9png-1-1024x231.png 1024w, http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/\u30bd\u30fc\u30b9png-1-300x68.png 300w, http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/\u30bd\u30fc\u30b9png-1-768x173.png 768w, http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/\u30bd\u30fc\u30b9png-1.png 1364w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>The generated data is stored in a variable of type <code>BitMatrix<\/code> (<code>bm<\/code>). By specifying the output format in the <code>writeToStream<\/code> method, you can save the generated QR code in your desired format. In this case, we output the QR code in PNG format.<\/p>\n\n\n\n<p>While the actual implementation involves handling API requests and returning the output result to the screen, I\u2019ll omit those details here.<\/p>\n\n\n\n<h3>Summary<\/h3>\n\n\n\n<p>Nowadays, if you just want to generate a QR code once for testing purposes, there\u2019s 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.<\/p>\n\n\n\n<p>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\u2019d be delighted.<\/p>\n\n\n\n<p>Stay tuned for the next engineer blog post!<\/p>\n\n\n\n<p><em>P.S. The content of the QR code includes a closing message!<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"310\" height=\"287\" src=\"http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/\u7de0\u3081.png\" alt=\"\" class=\"wp-image-5746\" srcset=\"http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/\u7de0\u3081.png 310w, http:\/\/dandelions.co.jp\/blog\/wp\/wp-content\/uploads\/2025\/01\/\u7de0\u3081-300x278.png 300w\" sizes=\"(max-width: 310px) 100vw, 310px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to our engineer blog, where we share our ongoing learning experiences. This post is part of Unit 0, wh &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/dandelions.co.jp\/blog\/blog\/2025\/01\/22\/engineer-blog-about-qr-code-generation\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;<strong>Engineer Blog \u2013 About QR Code Generation<\/strong>&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[8],"tags":[9],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paR9rw-1uZ","_links":{"self":[{"href":"http:\/\/dandelions.co.jp\/blog\/wp-json\/wp\/v2\/posts\/5765"}],"collection":[{"href":"http:\/\/dandelions.co.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dandelions.co.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dandelions.co.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/dandelions.co.jp\/blog\/wp-json\/wp\/v2\/comments?post=5765"}],"version-history":[{"count":1,"href":"http:\/\/dandelions.co.jp\/blog\/wp-json\/wp\/v2\/posts\/5765\/revisions"}],"predecessor-version":[{"id":5766,"href":"http:\/\/dandelions.co.jp\/blog\/wp-json\/wp\/v2\/posts\/5765\/revisions\/5766"}],"wp:attachment":[{"href":"http:\/\/dandelions.co.jp\/blog\/wp-json\/wp\/v2\/media?parent=5765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dandelions.co.jp\/blog\/wp-json\/wp\/v2\/categories?post=5765"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dandelions.co.jp\/blog\/wp-json\/wp\/v2\/tags?post=5765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}