Generating QR Code for Different Data - ByteScout
  • Home
  • /
  • Blog
  • /
  • Generating QR Code for Different Data

Generating QR Code for Different Data

QR codes are a form of 2-Dimensional barcode – QR is an acronym of Quick Response code, but they may also be referred to as Denso Barcodes. Created by Denso Wave in 1994, QR codes represented a fascinating step forward for the visual representation of binary data. Moving beyond the simple lines-and-spaces approach of previous barcodes, QR codes store information as a matrix, allowing a greater complexity of data and greater efficiency of space. Initially, the automotive sector was the main use for which QR codes were planned, and later they became broadly accepted as part of promotional campaigns and packaging: anywhere there needs to be an interface between physical/print media and digital media, QR codes are valuable. They are particularly popular specifically in mobile apps, where by means of a QR Code scanner app, one can easily scan a QR code to display text or access the campaign’s landing page.

QR Code SDK Features

QR Codes: how they hold data, and what platforms you can use

The information encoded in a QR code can be comprised of five standardized kinds of data numeric data (digits 0-9), alphanumeric data (digits, uppercase letters A-Z, characters (for example, space, %, $, +, -, *, /, etc.), Kanji characters and byte data.

There are a variety of options for accessing QR Code generator elements through software:

Creating QR Codes

While there are various complex development tools which enable you to create QR codes unless you’re playing with QR codes as a technical exercise, you actually need your QR code to be made so you can integrate it into a larger project; and that’s what you need to be able to spend your time on. The QR code generator from ByteScout allows you huge flexibility, including the ability to create QR codes with a form factor in compliance with more than 50 different standards, and allows insertion of data to barcodes from a range of sources and types, including geolocation, email, social media links, specific content you wish to highlight from your website, and more.

No installation is needed; the code is entirely web-based. Security is covered by the fact that all QR codes are removed from the server as soon as they are created, and QR codes are transmitted using SSL secure servers, making the tool safe for use.

The program also allows you to scan in existing QR codes, to analyze their function.

If you are doing a code project, however, you could compare your QR code created with to the product of your own dev process, as in the following example, which will create a QR code image, and allow information to be read from the QR code image:

import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;

public class QR_Code {
public static void main(String[] args) throws WriterException, IOException,
			NotFoundException {
		String QR_Code_Data = "Hey Universe!";
		String file_Path = "QR_Code.png";
		String char_set = "UTF-8"; // or "ISO-8859-1"
		Map hint_Map = new HashMap();
		Hint_Map.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
		createQRCode(QR_Code_Data, file_Path, char_set, hint_Map, 150, 150);
		System.out.println("Successful Creation of QR Code image!");

		System.out.println("Let’s read data from QR Code: "
				+ read_QR_Code(file_Path, char_set, hint_Map));
public static void createQRCode(String QR_Code_Data, String file_Path,
			String char_set, Map hint_Map, int QR_Code_height, int QR_Code_width)
			throws WriterException, IOException {
		BitMatrix matrix = new MultiFormatWriter().encode(
				new String(QR_Code_Data.getBytes(char_set), char_set),
				BarcodeFormat.QR_CODE, QR_Code_width, QR_Code_height, hint_Map);
		MatrixToImageWriter.writeToFile(matrix, filePath.substring(file_Path
				.lastIndexOf('.') + 1), new File(file_Path));
public static String read_QR_Code(String file_Path, String char_set, Map hint_Map)
			throws FileNotFoundException, IOException, NotFoundException {
		BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
				new BufferedImageLuminanceSource( FileInputStream(file_Path)))));

And from all of that, here’s what we get:

QR Code

And, as another example, try this. If you can’t follow the code, use the image to see the output!

import java.awt.Color;
import java.awt.Graphics2D;
import java.util.Hashtable;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;


public class QR_Code_Generation{
	public static void main(String[] args) throws WriterException, IOException {
		String QR_Code_Text = "";
		String Path_of_the_file = "E:\\Huda\\QRC.png";
		int size = 200;
		String Type_of_the_file = "png";
		File QR_File = new File (Path_of_the_file);
		createQRImage(QR_File, QR_Code_Text, size, Type_of_the_file);
		System.out.println("It’s generating smoothly!");
	private static void createQRImage(File QR_File, String QR_Code_Text, int size,
			String Type_of_the_file) throws WriterException, IOException {
		// Form the Byte-Matrix for the Quick Response Code that encodes the provided String
		Hashtable hint_Map = new Hashtable();
		hint_Map.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
		QRCodeWriter QR_Code_Writer = new QRCodeWriter();
		BitMatrix Matrix_byte = QR_Code_Writer.encode(QR_Code_Text,
				BarcodeFormat.QR_CODE, size, size, hint_Map);
		// Creation of Buffered-Image; it will hold the QR Code
		int Width_of_Matrix = Matrix_byte.getWidth();
		BufferedImage image = new BufferedImage(Width_of_Matrix, Width_of_Matrix,
		Graphics2D graphics = (Graphics2D) image.getGraphics();
		graphics.fillRect(0, 0, Width_of_Matrix, Width_of_Matrix);
		// By means of the Matrix_byte, paint as well as save the image

		for (int a = 0; a < Width_of_Matrix; a++) {
			for (int b = 0; b < Width_of_Matrix; b++) {
				if (Matrix_byte.get(a, b)) {
					graphics.fillRect(a, b, 1, 1);

The output of this code is shown below:

New QR Code

Using QR Codes on your site

One popular jQuery plugin for QR code generation is jquery.qrcode.js, which enables the user to add QR code to the web pages in an easy way, without depending on external services. It is based on a library that generates QR codes in a number of languages.

To use it, start by including it on your web page with the following tag:

After that, form a DOM element that will hold the generated QR code image. And after that, add the QR code to the container like so:

jquery(‘#qrcode’).qrcode(“Wow, it’s lovely to use this plugin”);

Generating a QR Code in Java can be a simple and smooth process if you use the right libraries, and this can be just the starting point. If you need a good way of introducing a digital interface-point to physical functionality, QR codes are a great bridge. Get started and see what they can do for you!


About the Author

ByteScout Team

ByteScout Team of Writers

ByteScout has a team of professional writers specialized in different technical topics. We select the best writers to cover interesting and trending topics for our readers. We love developers and we hope our articles help you learn about programming and programmers.