Overlaying Image in QR

Overlaying Image in QR

- 2 mins

Who should read this?

If you are into generating QR Codes and want to generate one which includes an image, like your company logo etc, then you are in the right place. This blog is NOT focused on explaining what QR Codes are and how they are used and the amount of data they can store. If you need information with that, refere Wikipedia, it has more than sufficient information for you.

If you are still with me, then get ready, open your IDE. We will be using Java and ZXing here.

Overlay Image in QR Code

These are pretty common types of QR Codes. This technique is specifically targetted at marketting/branding. Looking at these QR Codes, a user can instantly know who this QR belongs to and what he/she is supposed to do with it.

Examples of branded QR Codes

Steps to be performed

There are a number of steps to be performed while overlaying an image on a QR code. Like you might have noticed, all the QR Codes shows in the above image are layered i.e. the bottom layer is the actual QR and the top layer is the logo. We have to do the same with ZXing. Let us first see the steps :

  1. Create configuration that specifies the error correction
  2. Create a QR code as a BitMatrix, using ZXing, with your content
  3. Load QR Image into BufferedImage
  4. Resize the logo image that you want to overlay and get it in another BufferedImage object
  5. Calculate the difference between diamentions of QR Image and the Overlay Image
  6. Write the final Image

The following piece of code explains how I wrote the function. There may be many different ways to do this but this is the only one I am aware of. If you know of a different way of doing this, speak up in the comments!

The variables WIDTH, HEIGHT, BLACK, WHITE mark diamentions and color combination of the QR Code. If you are interested in the values that I used, here you go :

And this is how I wrote the getOverlay function.

In the line 8 and 9, I found out that If I reduced the overlay image by 6 times, it gave me the best results. However, in your case, you may want to play around with this value to see what suits you the best.

You can just copy the code and replace LOGO and content and it should straightaway work for you. If not, feel free to post queries in the comments.

  1. Wikipedia
  2. Google QR Codes
Pranjal Gore

Pranjal Gore

Software Developer | Aspiring Blogger

comments powered by Disqus
rss facebook twitter github gitlab youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora