QR CODE GENERATOR USING JAVA

We need to use this code for QR CODE GENERATOR USING JAVA 1)We need to use zxing-1.6-core.jar IMG-20141129-WA0000           2)We need to embed this code in Myeclipse or Netbeans or any IDE you are using ============================================

package com.shiva.generator;

import java.awt.Color;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import java.util.Hashtable;

import javax.imageio.ImageIO;

import com.google.zxing.BarcodeFormat;

import com.google.zxing.EncodeHintType;

import com.google.zxing.WriterException;

import com.google.zxing.common.BitMatrix;

//import com.google.zxing.common.ByteMatrix;

import com.google.zxing.qrcode.QRCodeWriter;

import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

 

public class GenerateQRCode {

 

/**

* @param args

* @throws WriterException

* @throws IOException

*/

public static void main(String[] args) throws WriterException, IOException {

String qrCodeText = “Hi i am the blogger shiva here”;

String filePath = “D:\\Shiva\\JD1.png”;

int size = 125;

String fileType = “png”;

File qrFile = new File(filePath);

createQRImage(qrFile, qrCodeText, size, fileType);

System.out.println(“DONE”);

}

 

private static void createQRImage(File qrFile, String qrCodeText, int size,

String fileType) throws WriterException, IOException {

// Create the ByteMatrix for the QR-Code that encodes the given String

Hashtable hintMap = new Hashtable();

hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

QRCodeWriter qrCodeWriter = new QRCodeWriter();

BitMatrix byteMatrix = qrCodeWriter.encode(qrCodeText,

BarcodeFormat.QR_CODE, size, size, hintMap);

// Make the BufferedImage that are to hold the QRCode

int matrixWidth = byteMatrix.getWidth();

BufferedImage image = new BufferedImage(matrixWidth, matrixWidth,

BufferedImage.TYPE_INT_RGB);

image.createGraphics();

 

Graphics2D graphics = (Graphics2D) image.getGraphics();

graphics.setColor(Color.WHITE);

graphics.fillRect(0, 0, matrixWidth, matrixWidth);

// Paint and save the image using the ByteMatrix

graphics.setColor(Color.BLACK);

 

for (int i = 0; i < matrixWidth; i++) {

for (int j = 0; j < matrixWidth; j++) {

if (byteMatrix.get(i, j)) {

graphics.fillRect(i, j, 1, 1);

}

}

}

ImageIO.write(image, fileType, qrFile);

}

 

}
————————————————————————–

3)Test it with your mobile after the qr pattern is geneated in the folder By installing QR code scanner App

Leave a Reply to assist you..

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s