a simple QRCode generation api for java built on top ZXING

Related tags

QRCode QRGen
Overview

Build Status Release

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.

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 {
        compile 'com.github.kenglxn.QRGen:javase:2.6.0'
    }

Maven:

    <dependencies>
        <dependency>
            <groupId>com.github.kenglxn.qrgen</groupId>
            <artifactId>javase</artifactId>
            <version>2.6.0</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 {
        compile 'com.github.kenglxn.QRGen:android:2.6.0'
    }

Maven:

    <dependencies>
        <dependency>
            <groupId>com.github.kenglxn.qrgen</groupId>
            <artifactId>android</artifactId>
            <version>2.6.0</version>
        </dependency>
    </dependencies>

Or you can clone and build yourself:

    git clone git://github.com/kenglxn/QRGen.git
    cd QRGen/
    mvn clean install

Usage:

// 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(outputStream);

// 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("[email protected]")
                    .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("[email protected]");
QRCode.from(email).file();

// encode mms data
MMS mms = new MMS("Hello World");
QRCode.from(mms).file();

// encode sms data
SMS sms = new SMS("Hello World");
QRCode.from(sms).file();

// encode MeCard data
MeCard johnDoe = new MeCard("John Doe");
johnDoe.setEmail("[email protected]");
johnDoe.setAddress("John Doe Street 1, 5678 Doestown");
johnDoe.setTelephone("1234");
QRCode.from(johnDoe).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();

// QRGen currently supports the following schemas:
// - BizCard
// - Bookmark
// - Email
// - GeoInfo
// - Girocode
// - GooglePlay
// - ICal
// - KddiAu
// - MMS
// - MeCard
// - SMS
// - Telephone
// - Url
// - VCard
// - Wifi
// - YouTube

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:

http://www.apache.org/licenses/LICENSE-2.0.html

Comments
  • Generating QR code

    Generating QR code

    Hi. I imported android-2.0-20140713.143342-8.jar to my project from "https://oss.sonatype.org/content/repositories/snapshots/net/glxn/qrgen/android/2.0-SNAPSHOT/" and then according to your README.md usage, i wrote this code on my activity: File file = QRCode.from("Hello World").file(); // override the image type to be JPG QRCode.from("Hello World").to(ImageType.JPG).file(); QRCode.from("Hello World").file("QRCode");

    However, it crashed the application. the logcat stated that "java.lang.NoClassDefFoundError: com.google.zxing.qrcode.QRCodeWriter." May i know how should i solve this?

    opened by YeeSuannn 25
  • VCard force stop on android

    VCard force stop on android

    VCard not working on SDK 10 gingerbread, forcebstop every time try to generate from it, NoSuchMethodException, I handled it but it's also not working, just give me the handled toast even the text fields not empty!

    opened by MuhamedFathy 16
  • No vector formats available

    No vector formats available

    no vector graphic formats EPS or SVG available. I want to have QR image with vector format for better print quality. Something like: QRCode.from("Hello World").to(ImageType.SVG).withSize(250, 250).file();

    opened by sytolk 12
  • Charset not specified

    Charset not specified

    It should be possible to specify the desired charset. I have special chars in the text I use to generate the QRCode and they are badly encoded when I read the genrated QRCode. I would suggest to use UTF-8 by default, to avoid this.

    opened by teemoo7 11
  • Examples from README just don't compile

    Examples from README just don't compile

    Examples from README just don't compile

    import net.glxn.qrgen.core.image.ImageType;
    import net.glxn.qrgen.core.scheme.EMail;
    import net.glxn.qrgen.core.scheme.MMS;
    import net.glxn.qrgen.core.scheme.MeCard;
    import net.glxn.qrgen.core.scheme.SMS;
    import net.glxn.qrgen.core.scheme.VCard;
    import net.glxn.qrgen.javase.QRCode;
    
    // https://github.com/kenglxn/QRGen
    public class GenerateQRCodeWithKenglxnQRGen {
    	protected static Logger logger = LoggerFactory.getLogger(GenerateQRCodeWithKenglxnQRGen.class);
    
    	public static void main(String[] args) {
    		....
    
    		// encode mms data
    		MMS mms = new MMS("Hello World");
    		QRCode.from(mms).file();
    
    		// encode sms data
    		SMS sms = new SMS("Hello World");
    		QRCode.from(sms).file();
    
    		// encode MeCard data
    		MeCard johnDoe2 = new MeCard("John Doe");
    		johnDoe.setEmail("[email protected]");
    		johnDoe.setAddress("John Doe Street 1, 5678 Doestown");
    		johnDoe.setTelephone("1234");
    		QRCode.from(johnDoe).file();
    
    • No such constructor
    • No such method

    image

    opened by paulvi 10
  • Unable to fetch from jitpack

    Unable to fetch from jitpack

    SBT seems to hang on this and eventually fails:

    https://jitpack.io/com/github/kenglxn/qrgen/javase/2.3.0/
    0.0% [          ] 0 B (0 B / s)
    

    trying same url in the browser results in connection being stuck as well. Attempt to open https://jitpack.io/com/github/kenglxn/qrgen/javase/ in the browser shows Tag or commit 'javase' not found. Rechecking.

    I do have jitpack repository added correctly, it used to work for a long time without any issue.

    opened by rusho 9
  • unable to resolve with android latest version

    unable to resolve with android latest version

    hi, i've updated my app and getting error after upgrading from 25 to 26, please help me to sort out this issue

    untitled compileSdkVersion 26 buildToolsVersion "26.0.1"

    opened by microcian 9
  • License compatibility issue

    License compatibility issue

    Hi, I've seen that under the hood your library is leveraging jfreesvg that is licensed under GPL v3. This situation is compatible with the Apache 2 License of QRGen? It seems that the 2 license are not compatible: http://www.apache.org/licenses/GPL-compatibility.html

    I'm missing something? Can I use your library in my commercial solution?

    Thanks very much

    Duccio

    opened by ducciovigolo 9
  • Unable to compile on Android when another library use zxing

    Unable to compile on Android when another library use zxing

    Hi,

    my app need to create and read a qr code, so i get your awesome library and another one for scanning purpose: https://github.com/dlazaro66/QRCodeReaderView

    but when i try to compile the compiler (Gradle - Android studio) failed :(

    This is the error : com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/BarcodeFormat;

    Do you have any idea to solve this problem ?

    Thanks.

    opened by ilmetu 8
  • #32 Added checkstyle plugin to pom with default sun coding conventions.

    #32 Added checkstyle plugin to pom with default sun coding conventions.

    Just added checkstyle plugin and standard sun conventions file. Must be adapted to desired configuration (don't know if you've changed default IDEA formatting).

    opened by atomfrede 8
  • problem with bitmap

    problem with bitmap

    I can't use any method in the library with the bitmap, only the given example in read me works, but if i want to add some methods like withCharset() or withWidth() it's just give me error!

    for example: final Bitmap bm = QRCode.from(et.getText().toString()).bitmap(); <-- That's works!

    final Bitmap bm = QRCode.from(et.getText().toString()).withSize(600, 600).withCharset("UTF-8").bitmap(); <-- Not working!

    Also the withColor() method don't work in general!

    Am new in programming actually and don't know how to use that or is this is a serious issue or not!

    opened by MuhamedFathy 7
  • com.google.zxing.NotFoundException in decode

    com.google.zxing.NotFoundException in decode

    Hi, when I call the decode method with or without map of hints I obtain this error: com.google.zxing.NotFoundException when something goes wrong. This error appears sometimes, randomly, and I can't understand the cause of it because the message is not enough verbose.

    Screenshot 2022-12-16 at 17 54 46

    opened by f-aliberti 0
Releases(3.0.1)
  • 3.0.1(Nov 28, 2022)

  • 3.0.0(Nov 28, 2022)

    What's Changed

    • Upgrade zxing version to newest possible by @wojciechUrbanski in https://github.com/kenglxn/QRGen/pull/128
    • Revert "Upgrade zxing version to newest possible" by @kenglxn in https://github.com/kenglxn/QRGen/pull/129
    • Upgrading zxing to newest version by @wojciechUrbanski in https://github.com/kenglxn/QRGen/pull/130
    • Resolves #142 Updated zxing and batik by @tr00per in https://github.com/kenglxn/QRGen/pull/143
    • fix build and update to java 11 by @kenglxn in https://github.com/kenglxn/QRGen/pull/152
    • Preparing release of 2.7.0 by @Lonzak in https://github.com/kenglxn/QRGen/pull/151

    New Contributors

    • @wojciechUrbanski made their first contribution in https://github.com/kenglxn/QRGen/pull/128
    • @Lonzak made their first contribution in https://github.com/kenglxn/QRGen/pull/151

    Thanks for the contribution! 🎉

    Full Changelog: https://github.com/kenglxn/QRGen/compare/2.6.0...3.0.0

    Source code(tar.gz)
    Source code(zip)
  • 2.7.0(Nov 24, 2022)

  • 2.6.0(Jul 18, 2019)

    • #122 from @dubiao dubiao/patch-1
      • Make createMatrix public
    • #113 from @tr00per tr00per/master
      • Added OutputStream as svg sink
    • #110 from @atomfrede atomfrede/95-add-svg-support-again
      • add svg support again
    • #104 from @moberwasserlechner moberwasserlechner/bugfix/groupid
      • chore(): fix groupId
    • #105 from @moberwasserlechner moberwasserlechner/bugfix/schema
      • Allow schema implementation in user projects

    Thank you for the contributions: @dubiao, @tr00per, @atomfrede, @moberwasserlechner

    Source code(tar.gz)
    Source code(zip)
  • 2.5.0(Jun 16, 2018)

  • 2.4.0(Jan 5, 2018)

    • #93 from @pawlidim
      • New qr code schema implementations QRGen Now Supports the following schemas:
        • BizCard
        • Bookmark
        • Email
        • GeoInfo
        • Girocode
        • GooglePlay
        • ICal
        • KddiAu
        • MMS
        • MeCard
        • SMS
        • Telephone
        • Url
        • VCard
        • Wifi
        • YouTube
    Source code(tar.gz)
    Source code(zip)
  • 2.3.0(Dec 21, 2017)

    • #87 from @flurdy
      • Zxing version 3.3.0
    • #83 from @Fleker
      • Added extended EnterpriseWifi class
    • #81 from @degendra
      • Update details on maven url placement for gradle builds in README.md
    Source code(tar.gz)
    Source code(zip)
  • 2.2.0(Dec 21, 2017)

  • 2.1.0(Dec 21, 2017)

    • #62 from @Botz
      • Add withColor() function for android
    • #58 from @killme2008
      • Fixed typo in readme
    • #57 from @ralfstuckert
      • Add support for Girocode and Wifi Schemes
    • #48 from @atomfrede
      • Cleanup svg and bitmap terminal operators
    • #47 from @ArielCabib
      • Enabling configuration of QR color
    • #46 from @fadils
      • fix typo in bitmap example in README.md
    • #44 from @atomfrede
      • Updated maven central badges in readme
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(Dec 21, 2017)

    • #42 from @jasdeep
      • fix camelcasing in phoneNumer
    • #41 from @atomfrede
      • Preparation for 2.0 release hiding svg api for now #28
    • #38 from @atomfrede
      • #32 Added checkstyle plugin to pom with default sun coding conventions
    • #37 from @atomfrede
      • Added dependency management
    • #36 from @atomfrede
      • Added bitmap() to android module
    • #35 from @atomfrede
      • #34 Extracted all versions into parent .pom
    • #33 from @kenglxn
      • reformatting. also replace tabs with spaces
    • #27 from @atomfrede
      • Add maven central badge to README.md
    • #26 from @atomfrede
      • Fixed QRCode Generation on android
    • #24 from @gmarizy
      • Improve performance of Bitmap generation
    • #25 from @atomfrede
      • Custom shadow class
    • #23 from @atomfrede
      • Fixed typo in readme
    • #21 from @atomfrede
      • Updated zxing to latest version
    • #20 from @avalax
      • changed project type from apklib to jar
    • #18 from @diegosouzapb
      • fix typo in example in README.md
    • #17 from @atomfrede
      • Make compatible with Android platform by introducing Modules and fixing #16
    • #15 from @atomfrede
      • Add example for utf-8 strings in vcard to README.md
    • #14 from @atomfrede
      • UTF-8 Encoding in VCard
    Source code(tar.gz)
    Source code(zip)
  • 1.4.0(Dec 21, 2017)

    • #9 from @sefator
      • New version of ZXING and method for setting any encode hint
    • #7 from @atomfrede
      • Added information about VCard encoding to readme
    • #6 from @atomfrede
      • Simple posibility to encode simple VCard/Contact data as QRCode
    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Dec 21, 2017)

QRCode 扫描二维码、扫描条形码、相册获取图片后识别、生成带 Logo 二维码、支持微博微信 QQ 二维码扫描样式

?? BGAQRCode-Android ?? 目录 功能介绍 常见问题 效果图与示例 apk Gradle 依赖 布局文件 自定义属性说明 接口说明 关于我 功能介绍 根据之前公司的产品需求,参考 barcodescanner 改的,希望能帮助到有生成二维码、扫描二维码、识别图片二维码等需求的猿友

王浩 7.7k Dec 29, 2022
QRCode Generator implemented in pure Kotlin

Creating QRCodes in Kotlin and Java is harder than it should be. QRCode-Kotlin aims to bring a simple, straightforward and customizable way to create QRCodes into the JVM domain, especially in the backend.

Rafael Lins 42 Dec 28, 2022
Barcode scanner library for Android, based on the ZXing decoder

ZXing Android Embedded Barcode scanning library for Android, using ZXing for decoding. The project is loosely based on the ZXing Android Barcode Scann

JourneyApps 5.3k Jan 4, 2023
Generate Qr Code using ZXING with a logo if needed

QrGeneratorWithLogo Generate Qr Code using ZXING with a logo if needed Download the Helper file and use it 1- add zxing lib into your project implem

null 0 Mar 14, 2022
Android library for creating QR-codes with logo, custom pixel/eyes shapes, background image. Powered by ZXing.

custom-qr-generator Android library for creating QR-codes with logo, custom pixel/eyes shapes, background image. Powerd by ZXing. Installation To get

Alexander Zhirkevich 34 Dec 17, 2022
MyQRScanner - Simple app for reading QR Code

My QRCode Scanner Simple app for reading QR Code Technologies Jetpack Compose Ca

Joselaine Aparecida dos Santos 4 Feb 17, 2022
simple qrcode scan application

qrcode simple qrcode scan application

Geovani Amaral 6 Oct 5, 2022
ZXing ("Zebra Crossing") barcode scanning library for Java, Android

Project in Maintenance Mode Only The project is in maintenance mode, meaning, changes are driven by contributed patches. Only bug fixes and minor enha

ZXing Project 30.5k Dec 27, 2022
QRCode 扫描二维码、扫描条形码、相册获取图片后识别、生成带 Logo 二维码、支持微博微信 QQ 二维码扫描样式

?? BGAQRCode-Android ?? 目录 功能介绍 常见问题 效果图与示例 apk Gradle 依赖 布局文件 自定义属性说明 接口说明 关于我 功能介绍 根据之前公司的产品需求,参考 barcodescanner 改的,希望能帮助到有生成二维码、扫描二维码、识别图片二维码等需求的猿友

王浩 7.7k Dec 29, 2022
QRCode Generator implemented in pure Kotlin

Creating QRCodes in Kotlin and Java is harder than it should be. QRCode-Kotlin aims to bring a simple, straightforward and customizable way to create QRCodes into the JVM domain, especially in the backend.

Rafael Lins 42 Dec 28, 2022
Barcode scanner library for Android, based on the ZXing decoder

ZXing Android Embedded Barcode scanning library for Android, using ZXing for decoding. The project is loosely based on the ZXing Android Barcode Scann

JourneyApps 5.3k Jan 4, 2023
Generate Qr Code using ZXING with a logo if needed

QrGeneratorWithLogo Generate Qr Code using ZXING with a logo if needed Download the Helper file and use it 1- add zxing lib into your project implem

null 0 Mar 14, 2022
Android library for creating QR-codes with logo, custom pixel/eyes shapes, background image. Powered by ZXing.

custom-qr-generator Android library for creating QR-codes with logo, custom pixel/eyes shapes, background image. Powerd by ZXing. Installation To get

Alexander Zhirkevich 34 Dec 17, 2022
Pure Java code generation tool for generating a fully functional ContentProvider for Android.

RoboCoP RoboCoP is a Java library that can generate a fully-functional ContentProvider from a simple JSON schema file. Get the latest version from our

Rain 246 Dec 29, 2022
Runtime code generation for the Java virtual machine.

Byte Buddy runtime code generation for the Java virtual machine Byte Buddy is a code generation and manipulation library for creating and modifying Ja

Rafael Winterhalter 5.3k Jan 7, 2023
Grazel is a Gradle plugin to automate generation of valid Bazel files for a given Android/Kotlin/Java project.

Grazel Grazel stands for Gradle to Bazel. It is a Gradle plugin that enables you to migrate Android projects to Bazel build system in an incremental a

Grab 228 Jan 2, 2023
Experimental Graphviz code generation POC built with Jetpack Compose compiler/runtime.

Compose Dot Experimental proof of concept to generate GraphViz dot code via Jetpack Compose's tree management. Valid dot file content can be generated

Arunkumar 29 Sep 14, 2022
NeoPOP was created with one simple goal; to create the next generation of a beautiful, affirmative design system

NeoPop is CRED's inbuilt library for using NeoPop components in your app

CRED 254 Dec 29, 2022
RedditNews - A simple application to display the top news from the Reddit API site and save your favorites to a local database.

RedditNews - A simple application to display the top news from the Reddit API site and save your favorites to a local database. Arch

null 1 Aug 28, 2022
SocyMusic is an open-source Android music player written in Java with the aim of creating an easy-to-use app for exchanging and listening to top-quality music. Help us create it!

SocyMusic SocyMusic is an open-source Android music player written entirely in Java. It's objectives are to provide top-quality music to everyone for

Benji 23 Dec 26, 2022