Top Related Projects
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
High-quality QR Code generator library in Java, TypeScript/JavaScript, Python, Rust, C++, C.
Cross-browser QRCode generator for javascript
A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
QR Code Generator implementation in JavaScript, Java and more.
Quick Overview
QRGen is a simple and lightweight Java library for generating QR codes. It provides a fluent interface for creating QR codes with various options, including size, format, and error correction level. The library supports multiple output formats such as images, SVG, and byte arrays.
Pros
- Easy to use with a fluent API
- Supports multiple output formats (PNG, JPG, GIF, SVG, and more)
- Lightweight with minimal dependencies
- Actively maintained and regularly updated
Cons
- Limited to QR code generation only (no scanning functionality)
- Lacks advanced customization options for QR code appearance
- Documentation could be more comprehensive
Code Examples
Creating a simple QR code as a PNG file:
QRCode.from("Hello, World!").file("qr-code.png");
Generating a QR code with custom size and error correction:
QRCode.from("https://example.com")
.withSize(250, 250)
.withErrorCorrection(ErrorCorrectionLevel.H)
.file("custom-qr.png");
Creating a QR code as an SVG:
String svg = QRCode.from("SVG QR Code").svg();
Getting Started
To use QRGen in your Java project, add the following dependency to your Maven pom.xml
file:
<dependency>
<groupId>net.glxn.qrgen</groupId>
<artifactId>javase</artifactId>
<version>2.0</version>
</dependency>
For Gradle, add this to your build.gradle
file:
implementation 'net.glxn.qrgen:javase:2.0'
After adding the dependency, you can start generating QR codes using the examples provided above.
Competitor Comparisons
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
Pros of ZXing
- More comprehensive barcode library, supporting multiple formats beyond QR codes
- Actively maintained with regular updates and a large community
- Offers both encoding and decoding capabilities for various barcode types
Cons of ZXing
- Larger library size, which may impact application size and performance
- Steeper learning curve due to its extensive feature set
- More complex setup and integration process compared to QRGen
Code Comparison
ZXing (Generating QR code):
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height);
BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
QRGen (Generating QR code):
ByteArrayOutputStream out = QRCode.from(content).to(ImageType.PNG).stream();
Summary
ZXing is a more feature-rich and versatile barcode library, supporting multiple formats and offering both encoding and decoding capabilities. However, this comes at the cost of increased complexity and library size. QRGen, on the other hand, focuses specifically on QR code generation, providing a simpler and more lightweight solution for projects that only require QR code functionality.
High-quality QR Code generator library in Java, TypeScript/JavaScript, Python, Rust, C++, C.
Pros of QR-Code-generator
- More comprehensive and feature-rich, supporting a wider range of QR code types and options
- Implements the QR code specification from scratch, providing a deeper understanding and control
- Available in multiple programming languages (C++, JavaScript, Python, Java)
Cons of QR-Code-generator
- More complex to use, requiring more setup and configuration
- Less focused on ease of use and quick implementation
- May have a steeper learning curve for beginners
Code Comparison
QR-Code-generator (Java):
QrCode qr = QrCode.encodeText("Hello, world!", QrCode.Ecc.MEDIUM);
BufferedImage img = qr.toImage(4, 10);
ImageIO.write(img, "png", new File("qr-code.png"));
QRGen (Java):
File file = QRCode.from("Hello, world!")
.to(ImageType.PNG)
.withSize(250, 250)
.file();
QR-Code-generator offers more granular control over the QR code generation process, while QRGen provides a more streamlined and user-friendly API for quick implementation. The choice between the two depends on the specific requirements of the project and the developer's familiarity with QR code specifications.
Cross-browser QRCode generator for javascript
Pros of qrcodejs
- Pure JavaScript implementation, no server-side processing required
- Supports various output formats (Canvas, Table, SVG)
- Lightweight and easy to integrate into web applications
Cons of qrcodejs
- Limited to JavaScript environments, not suitable for server-side or mobile app development
- Fewer customization options compared to QRGen
- Less actively maintained (last update was in 2020)
Code Comparison
QRGen (Java):
QRCode.from("Hello, World!").withSize(250, 250).file();
qrcodejs (JavaScript):
var qrcode = new QRCode(document.getElementById("qrcode"), {
text: "Hello, World!",
width: 250,
height: 250
});
Summary
QRGen is a Java-based library offering more flexibility for server-side and mobile app development, while qrcodejs is a lightweight JavaScript solution ideal for web applications. QRGen provides more customization options and is more actively maintained. However, qrcodejs excels in simplicity and ease of integration for web-based projects, requiring no server-side processing.
A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
Pros of jsQR
- JavaScript-based, allowing for client-side QR code scanning in web browsers
- Supports real-time QR code detection from video streams
- Lightweight and easy to integrate into web applications
Cons of jsQR
- Limited to QR code scanning/reading functionality
- May have performance limitations for large-scale or high-speed scanning
Code Comparison
QRGen (Java):
QRCode qrCode = QRCode.from("Hello, World!")
.withSize(250, 250)
.to(ImageType.PNG);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
qrCode.writeTo(stream);
jsQR (JavaScript):
const code = jsQR(imageData.data, imageData.width, imageData.height);
if (code) {
console.log("Found QR code", code.data);
}
Key Differences
- QRGen focuses on QR code generation, while jsQR specializes in QR code scanning
- QRGen is Java-based, suitable for server-side or desktop applications, whereas jsQR is JavaScript-based for web applications
- QRGen offers more customization options for QR code generation, while jsQR provides real-time scanning capabilities
Both libraries serve different purposes and can be complementary in a full-stack application where QR code generation and scanning are required.
QR Code Generator implementation in JavaScript, Java and more.
Pros of qrcode-generator
- Supports multiple programming languages (JavaScript, Java, C++, etc.)
- Provides more customization options for QR code generation
- Has a longer development history and larger community
Cons of qrcode-generator
- Less straightforward API compared to QRGen
- Requires more setup and configuration for basic usage
- Documentation can be less comprehensive for some language implementations
Code Comparison
QRGen:
QRCode.from("Hello, World!").file();
qrcode-generator (JavaScript):
var qr = qrcode(0, 'M');
qr.addData('Hello, World!');
qr.make();
var imgTag = qr.createImgTag();
QRGen offers a more concise and straightforward API for basic QR code generation, while qrcode-generator provides more flexibility and customization options at the cost of slightly more verbose code.
Both libraries are actively maintained and have their strengths. QRGen is more focused on Java and Android development, while qrcode-generator offers multi-language support. The choice between them depends on the specific project requirements, target platform, and desired level of customization.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
QRGen: a simple QRCode generation api for java built on top ZXING
Please consider sponsoring the work on QRGen
Dependencies:
ZXING: http://code.google.com/p/zxing/
Get it:
QRGen consists of three modules: core
, javase
and android
.
As of 2.1.0 QRGen is available from jitpack.io. QRGen is no longer deployed to maven central (ref: #61). Older releases are available from Maven Central Repository.
As of 3.0.1 java 11 is required. Latest java 8 version is 2.7.0.
Maven:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Gradle:
allprojects {
repositories {
// ...
maven { url "https://jitpack.io" }
}
}
Nexus proxy setup for jitpack
See https://github.com/jitpack/jitpack.io/issues/506 for solution.
(thanks to @LTheobald for the heads up)
Java Application
When developing a Java application you need to add javase
module to your list of dependencies. The required core
module will be added automatically by your build system:
Gradle:
dependencies {
implementation 'com.github.kenglxn.QRGen:javase:3.0.1'
}
Maven:
<dependencies>
<dependency>
<groupId>com.github.kenglxn.QRGen</groupId>
<artifactId>javase</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
Android
When you want to use QRGen inside your android application you need to add the android
module to your list of dependencies. The required core
module will be added automatically by your build system:
Gradle:
dependencies {
implementation 'com.github.kenglxn.QRGen:android:3.0.1'
}
Maven:
<dependencies>
<dependency>
<groupId>com.github.kenglxn.QRGen</groupId>
<artifactId>android</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
Or you can clone and build yourself:
git clone git://github.com/kenglxn/QRGen.git
cd QRGen/
mvn clean install
Usage:
public class Demo {
public static void main(String[] args) {
// get QR file from text using defaults
File file = QRCode.from("Hello World").file();
// get QR stream from text using defaults
ByteArrayOutputStream stream = QRCode.from("Hello World").stream();
// override the image type to be JPG
QRCode.from("Hello World").to(ImageType.JPG).file();
QRCode.from("Hello World").to(ImageType.JPG).stream();
// override image size to be 250x250
QRCode.from("Hello World").withSize(250, 250).file();
QRCode.from("Hello World").withSize(250, 250).stream();
// override size and image type
QRCode.from("Hello World").to(ImageType.GIF).withSize(250, 250).file();
QRCode.from("Hello World").to(ImageType.GIF).withSize(250, 250).stream();
// override default colors (black on white)
// notice that the color format is "0x(alpha: 1 byte)(RGB: 3 bytes)"
// so in the example below it's red for foreground and yellowish for background, both 100% alpha (FF).
QRCode.from("Hello World").withColor(0xFFFF0000, 0xFFFFFFAA).file();
// supply own outputstream
QRCode.from("Hello World").to(ImageType.PNG).writeTo(new ByteArrayOutputStream());
// supply own file name
QRCode.from("Hello World").file("QRCode");
// supply charset hint to ZXING
QRCode.from("Hello World").withCharset("UTF-8");
// supply error correction level hint to ZXING
QRCode.from("Hello World").withErrorCorrection(ErrorCorrectionLevel.L);
// supply any hint to ZXING
QRCode.from("Hello World").withHint(EncodeHintType.CHARACTER_SET, "UTF-8");
// encode contact data as vcard using defaults
VCard johnDoe = new VCard("John Doe")
.setEmail("john.doe@example.org")
.setAddress("John Doe Street 1, 5678 Doestown")
.setTitle("Mister")
.setCompany("John Doe Inc.")
.setPhoneNumber("1234")
.setWebsite("www.example.org");
QRCode.from(johnDoe).file();
// encode email data
EMail email = new EMail("John.Doe@example.org");
QRCode.from(email).file();
// encode mms data
MMS mms = new MMS("8675309", "Hello Jenny");
QRCode.from(mms).file();
// encode sms data
SMS sms = new SMS("8675309", "Hello Jenny");
QRCode.from(sms).file();
// encode MeCard data
MeCard janeDoe = new MeCard("Jane Doe");
janeDoe.setEmail("john.doe@example.org");
janeDoe.setAddress("John Doe Street 1, 5678 Doestown");
janeDoe.setTelephone("1234");
QRCode.from(janeDoe).file();
// if using special characters don't forget to supply the encoding
VCard johnSpecial = new VCard("Jöhn Dɵe")
.setAddress("Ã«Ã¥Ã¤Ã¶Æ Sträät 1, 1234 Döestüwn");
QRCode.from(johnSpecial).withCharset("UTF-8").file();
}
}
Java SE only
When using java you can create svg files via .svg()
terminal operator:
File file = QRCode.from("www.example.org").svg();
File file = QRCode.from("www.example.com").withSize(250, 250).withColor(30, 90).svg();
It's also possible to write svg to an OutputStream
with terminal operation:
OutputStream outs = // ...
QRCode.from("www.example.org").svg(outs);
Android only
On Android you have a special method bitmap()
which returns a android.graphics.Bitmap
without creating a File
object before, so you can use the generated android.graphics.Bitmap
immediately inside an ImageView
:
Bitmap myBitmap = QRCode.from("www.example.org").bitmap();
ImageView myImage = (ImageView) findViewById(R.id.imageView);
myImage.setImageBitmap(myBitmap);
License:
Top Related Projects
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
High-quality QR Code generator library in Java, TypeScript/JavaScript, Python, Rust, C++, C.
Cross-browser QRCode generator for javascript
A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
QR Code Generator implementation in JavaScript, Java and more.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot