This mind blowing code is implemented and provided by Meghali Anand from MAIT, College, Ghaziabad.
Using this code we can create a QR Code from the string.
Means using the data of string we can generate a QR Code. This QR Code can be scanned using the scanner available with any smart phone.
Before using this code we need to download three jar files (that keeps the API to implement this code).
Names of jar files and their links are given below
1. qrgen-1.2.jar to load 'qrgen-1.2.jar' click here
2. zxing-core-1.7.jar to load 'zxing-core-1.7.jar' click here
3. zxing-j2se-1.7.jar to load 'zxing-j2se-1.7.jar' click here
After downloading the jar files, please follow given guidelines
1. Create a Java Project in Eclipse IDE
2. Attach jar files using build-path approach
3. Create a TestQR.java file
4. Copy and paste the code inside TestQR.java file
Note: Please save this code inside TestQR.java file
import java.io.FileOutputStream;
import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;
public class TestQR
{
public static void main(String[] args)
{
try
{
// create a string !!
// note: data of this string will be translated to a QR code
String myString = "Its magic it magic";
// get the object of QRCode !!
// note: from() is a static method of QRCode class that returns
// the object of QRCode using the string
QRCode qrc = QRCode.from(myString);
// specify the type of format in which the QR code will be shown
// note: here i have specified the type JPG
qrc = qrc.to(ImageType.JPG);
// open a file in write mode
// note: to open a file in write mode we are using FileOutputStream class
// the file will be created inside D: drive (we can also change the location of file)
// just change the value of filePath variable
String filePath = "D:\\demo.jpeg";
// now open this file in write mode
FileOutputStream fos = new FileOutputStream(filePath);
// store the data of QR code on the file
// note: which was opened in write mode
qrc.writeTo(fos);
// close the file
fos.close();
System.out.println("File has been created in D: drive...\n"
+ "please go there and check");
}
catch (Exception e)
{
// show the line number and cause of exception
e.printStackTrace();
}
} // end of main method
} // end of class
The QR Code generated by the code is =>>
Using this code we can create a QR Code from the string.
Means using the data of string we can generate a QR Code. This QR Code can be scanned using the scanner available with any smart phone.
Before using this code we need to download three jar files (that keeps the API to implement this code).
Names of jar files and their links are given below
1. qrgen-1.2.jar to load 'qrgen-1.2.jar' click here
2. zxing-core-1.7.jar to load 'zxing-core-1.7.jar' click here
3. zxing-j2se-1.7.jar to load 'zxing-j2se-1.7.jar' click here
After downloading the jar files, please follow given guidelines
1. Create a Java Project in Eclipse IDE
2. Attach jar files using build-path approach
3. Create a TestQR.java file
4. Copy and paste the code inside TestQR.java file
Note: Please save this code inside TestQR.java file
import java.io.FileOutputStream;
import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;
public class TestQR
{
public static void main(String[] args)
{
try
{
// create a string !!
// note: data of this string will be translated to a QR code
String myString = "Its magic it magic";
// get the object of QRCode !!
// note: from() is a static method of QRCode class that returns
// the object of QRCode using the string
QRCode qrc = QRCode.from(myString);
// specify the type of format in which the QR code will be shown
// note: here i have specified the type JPG
qrc = qrc.to(ImageType.JPG);
// open a file in write mode
// note: to open a file in write mode we are using FileOutputStream class
// the file will be created inside D: drive (we can also change the location of file)
// just change the value of filePath variable
String filePath = "D:\\demo.jpeg";
// now open this file in write mode
FileOutputStream fos = new FileOutputStream(filePath);
// store the data of QR code on the file
// note: which was opened in write mode
qrc.writeTo(fos);
// close the file
fos.close();
System.out.println("File has been created in D: drive...\n"
+ "please go there and check");
}
catch (Exception e)
{
// show the line number and cause of exception
e.printStackTrace();
}
} // end of main method
} // end of class
The QR Code generated by the code is =>>