kenglxn / qrgen Goto Github PK
View Code? Open in Web Editor NEWa simple QRCode generation api for java built on top ZXING
Home Page: http://glxn.net/2012/03/10/qrgen-a-small-wrapper-on-top-of-zxing-for-generating-qrcodes-in-java
a simple QRCode generation api for java built on top ZXING
Home Page: http://glxn.net/2012/03/10/qrgen-a-small-wrapper-on-top-of-zxing-for-generating-qrcodes-in-java
Hello, could you add an open source license so others can use and improve your project easily?
Thank you!
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();
Please update Android library in repo, I have used it from maven repo, but QRCode class doesn't have all required methods, that are present in you git repo by the way, so I have to extend AbstractQRCode class.
Methods like withSize, to are not implemented.
Current QRCode class content if following
import android.graphics.Bitmap;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import net.glxn.qrgen.core.AbstractQRCode;
import net.glxn.qrgen.core.exception.QRGenerationException;
import net.glxn.qrgen.core.image.ImageType;
import net.glxn.qrgen.core.scheme.VCard;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
public class QRCode extends AbstractQRCode {
protected final String text;
protected QRCode(String text) {
this.text = text;
qrWriter = new QRCodeWriter();
}
/**
* Create a QR code from the given text. <br/>
* <br/>
* <p/>
* There is a size limitation to how much you can put into a QR code. This
* has been tested to work with up to a length of 2950 characters.<br/>
* <br/>
* <p/>
* The QRCode will have the following defaults: <br/>
* {size: 100x100}<br/>
* {imageType:PNG} <br/>
* <br/>
* <p/>
* Both size and imageType can be overridden: <br/>
* Image type override is done by calling
* {@link AbstractQRCode#to(net.glxn.qrgen.core.image.ImageType)} e.g.
* QRCode.from("hello world").to(JPG) <br/>
* Size override is done by calling {@link AbstractQRCode#withSize} e.g.
* QRCode.from("hello world").to(JPG).withSize(125, 125) <br/>
*
* @param text the text to encode to a new QRCode, this may fail if the text
* is too large. <br/>
* @return the QRCode object <br/>
*/
public static QRCode from(String text) {
return new QRCode(text);
}
/**
* Creates a a QR Code from the given {@link VCard}.
* <p/>
* The QRCode will have the following defaults: <br/>
* {size: 100x100}<br/>
* {imageType:PNG} <br/>
* <br/>
*
* @param vcard the vcard to encode as QRCode
* @return the QRCode object
*/
public static QRCode from(VCard vcard) {
return new QRCode(vcard.toString());
}
/**
* Overrides the imageType from its default {@link net.glxn.qrgen.core.image.ImageType#PNG}
*
* @param imageType the {@link net.glxn.qrgen.core.image.ImageType} you would like the resulting QR to be
* @return the current QRCode object
*/
public QRCode to(ImageType imageType) {
this.imageType = imageType;
return this;
}
/**
* Overrides the size of the qr from its default 125x125
*
* @param width the width in pixels
* @param height the height in pixels
* @return the current QRCode object
*/
public QRCode withSize(int width, int height) {
this.width = width;
this.height = height;
return this;
}
/**
* Overrides the default charset by supplying a {@link com.google.zxing.EncodeHintType#CHARACTER_SET} hint to {@link
* com.google.zxing.qrcode.QRCodeWriter#encode}
*
* @return the current QRCode object
*/
public QRCode withCharset(String charset) {
return withHint(EncodeHintType.CHARACTER_SET, charset);
}
/**
* Overrides the default error correction by supplying a {@link com.google.zxing.EncodeHintType#ERROR_CORRECTION} hint to
* {@link com.google.zxing.qrcode.QRCodeWriter#encode}
*
* @return the current QRCode object
*/
public QRCode withErrorCorrection(ErrorCorrectionLevel level) {
return withHint(EncodeHintType.ERROR_CORRECTION, level);
}
/**
* Sets hint to {@link com.google.zxing.qrcode.QRCodeWriter#encode}
*
* @return the current QRCode object
*/
public QRCode withHint(EncodeHintType hintType, Object value) {
hints.put(hintType, value);
return this;
}
/**
* Returns a {@link android.graphics.Bitmap} without creating a {@link java.io.File} first.
*
* @return {@link android.graphics.Bitmap} of this QRCode
*/
public Bitmap bitmap() {
try {
return MatrixToImageWriter.toBitmap(createMatrix(text));
} catch (WriterException e) {
throw new QRGenerationException("Failed to create QR image from text due to underlying exception", e);
}
}
@Override
public File file() {
File file;
try {
file = createTempFile();
MatrixToImageWriter.writeToFile(createMatrix(text), imageType.toString(), file);
} catch (Exception e) {
throw new QRGenerationException("Failed to create QR image from text due to underlying exception", e);
}
return file;
}
@Override
public File file(String name) {
File file;
try {
file = createTempFile(name);
MatrixToImageWriter.writeToFile(createMatrix(text), imageType.toString(), file);
} catch (Exception e) {
throw new QRGenerationException("Failed to create QR image from text due to underlying exception", e);
}
return file;
}
@Override
protected void writeToStream(OutputStream stream) throws IOException, WriterException {
MatrixToImageWriter.writeToStream(createMatrix(text), imageType.toString(), stream);
}
}
when trying to use the snippet
QRCode.from("www.example.org").bitmap();
no bitmap()
method is found
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.
GMPM: getGoogleAppId failed with status: 10
GMPM: Uploading is not possible. App measurement disabled
AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: net.glxn.qrgen.android.QRCode
Could you please adds a image overlay to a qrcode?
Hey there,
We have used QRGen in a program we're developing. It's great and we really appreciate you sharing your work. We'd like to attribute your hard work to you by including a copyright notice in our documentation. However, we haven't been able to find one in the source or on the site. Who is the copyright holder and what is the year of the copyright?
Is this right?
Copyright (C) 2013 Frederik Hahne, Ken Gullaksen, Bitdeli Chef
Thanks in advance!
What about withColor()
method in android?
why it's only available in java se version, and when it will be available in android?!
Right now it seems like your Wi-Fi QR code generator only supports WEP and WPA, but not enterprise (where there's both a username and password).
I propose adding support for enterprise level Wi-Fi based on this guide.
Hello,
I think latest version is missing from maven. I can only find 1.4
If this is to work on android, QRGen can not depend on and use classes in the javase part of zxing.
see this related stackoverflow post: http://stackoverflow.com/questions/15221775/error-when-using-qrgen-library-to-generate-qr-code
git clone git://github.com/kenglxn/QRGen.git
cd QRGen/
mvn clean install
I built the library using these commands and am now getting this errors cannot access VCard class file for net.glxn.qrgen.core.scheme.VCard not found when building the project on android studio.
Is it possible to get rid of the white border arround the QR-Code?
Can you put a jar builded by jdk 1.6 to repository of maven?
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?
The generated QR code never covers the complete image because the generator always adds some border around it. One issue is that the dimension of the QR code does behave propotional to the dimension of the target image including the border. The problem is when you change the size of the image by one pixel the size of the QR code gets increased by 10 pixel wheareas the border size gets decreased by 9 pixels. This is not propotional to a change by one pixel.
A reproducible example where the actual QR code gets a lot smaller by changeing the image size by only one pixel:
Since modern readers do not need the 4 block margin, it would be nice to have the margin hint http://zxing.github.io/zxing/apidocs/com/google/zxing/EncodeHintType.html#MARGIN available.
That's pretty much the same as the charset hint. I have done this myself, being a total java noob, but it would be nice to have it in the official version.
Thanks, Mathias
I need to get around to doing this soon.
When 2.0 is released, remember to update the Readme as well.
Using Android Studio adding
dependencies {
compile ("net.glxn.qrgen:android:2.0-SNAPSHOT")
compile fileTree(dir: 'libs', include: ['*.jar'])
}
to build.gradle.
Error:
failed to find: net.glxn.qrgen:android:2.0-SNAPSHOT
What am I doing wrong? Please help.
Calling QRCode.stream() fails on Google AppEngine. The BufferedImage used by the unterlying zxing library is not whitelisted (see https://developers.google.com/appengine/docs/java/jrewhitelist). As a result, the qrgen library cannot be used in GAE applications at the moment. Are there any plans to change the library so that it can be used on App Engine?
REST-based QR code generators exist. But to reduce latency I would prefer generating the code inside of my GAE app (instead of talking to a REST service).
[INFO] Caused by: java.lang.NoClassDefFoundError: java.awt.image.BufferedImage is a restricted class. Please see the Google App Engine developer's guide for more details.
[INFO] at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
[INFO] at com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(MatrixToImageWriter.java:55)
[INFO] at com.google.zxing.client.j2se.MatrixToImageWriter.writeToStream(MatrixToImageWriter.java:117)
[INFO] at com.google.zxing.client.j2se.MatrixToImageWriter.writeToStream(MatrixToImageWriter.java:109)
[INFO] at net.glxn.qrgen.QRCode.writeToStream(QRCode.java:202)
[INFO] at net.glxn.qrgen.QRCode.stream(QRCode.java:180)
jcenter上只有2.0这个版本 ,README里写的是2.2.0,是README写错了,还是jar包没有传
https://jcenter.bintray.com/net/glxn/qrgen/javase/
Come to think of it, the fix in #14 probably is not a good idea, as I believe it would override charset hint if supplied. I also think the VCard should use System.lineSeparator() instead of \n to work properly across platforms.
I added the following line "compile 'com.github.kenglxn.QRGen:android:2.1.0'" on my gradle file inside dependencies but I get this error Failed to resolve: com.github.kenglxn.QRGen:android:2.1.0
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!
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.
Its have only two types supported now (Text and VCard). If I open this page
http://goqr.me/#t=call
on the point 1. its have 9 types: Call, URL, SMS, WIFI, Location.. is missing
I suppose that all types are string formatted with some tags like VCard.toString() but I cant find info for this?
I have found WiFi schema:
core/src/test/java/net/glxn/qrgen/core/scheme/WifiTest.java
Do you have schema for Call ? (phone number)
I have found here http://sixrevisions.com/web-development/qr-codes-uri-schemes/
tel:
this is very helpful
https://github.com/zxing/zxing/blob/master/core/src/test/java/com/google/zxing/client/result/ParsedReaderResultTestCase.java
it will be good if its have info in README for the different schema types. I can provide PR or this is better to be set with Enum before Text?
It's not a bug but a suggestion. Could QRGen output bitmap in addition of JPG, GIF and PNG ? Android need bitmap format for display. Just an idea, qrgen-android-exemple could change from:
File f = QRCode.from("https://github.com/kenglxn/QRGen").to(ImageType.JPG).file();
Bitmap myBitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageView);
myImage.setImageBitmap(myBitmap);
to:
Bitmap myBitmap = QRCode.from("https://github.com/kenglxn/QRGen").bitmap();
ImageView myImage = (ImageView) findViewById(R.id.imageView);
myImage.setImageBitmap(myBitmap);
Since QRGen already produce the bitmap internally, it will avoid to compress it in PNG, then to put it on a file, then the BitmapFactory thing.
need to tag previous releases so jitpack can make them available
make use of dependencyManagement and pluginManagement. All versions should be properties in the parent pom.
Was getting the following error:
Caused by: java.lang.UnsupportedClassVersionError: net/glxn/qrgen/javase/QRCode : Unsupported major.minor version 51.0
Create a checkstyle that validates code formatting according to my Intellij IDEA settings
Dear Coder, I enjoy using your qrgen library a lot! Thanks for the work.
Today I wanted to use your library through maven and used the dependencies listed on this page : http://kenglxn.github.io/QRGen/
But the repository seems to be unavailable. There are also other people dealing with this problem on stackoverflow: http://stackoverflow.com/questions/13379372/including-qrgen-in-pom-xml
Would be nice if you took a look at it.
add SVG QR Code rendering
I added compile 'com.github.kenglxn.QRGen:javase:2.2.0' to my android project. However, I ended up getting an error says "Failed to resolve github.kenglxn.QRGen:javase:2.2.0". Is there any other dependency should be added?
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
also change readme to reflect new setup
I'm writing a web app with Google App Engine. I found your library and I'm very interested in using it to generate QR codes. However I have an exception because you're creating a temporary file when I use
File file = QRCode.from("Hello World").file();
It generate a net.glxn.qrgen.core.exception.QRGenerationException
Do u know how can I solve this issue?
I use this to make bitmap
Bitmap qrCode = QRCode.from(macAddress).withSize(200, 200).bitmap();
imageView.setImageBitmap(qrCode);
but show error:
java.lang.VerifyError: net/glxn/qrgen/android/QRCode
at com.bitmain.bmrobot.activity.MainActivity.onOptionsItemSelected(MainActivity.java:198)
at android.app.Activity.onMenuItemSelected(Activity.java:2607)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:408)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:198)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:107)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:107)
at android.support.v7.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:69)
at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:206)
at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:777)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:817)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:156)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:964)
at android.support.v7.view.menu.MenuPopup.onItemClick(MenuPopup.java:127)
at android.widget.AdapterView.performItemClick(AdapterView.java:299)
at android.widget.AbsListView.performItemClick(AbsListView.java:1115)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2928)
at android.widget.AbsListView$3.run(AbsListView.java:3691)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5028)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
i use the android-23 SDK,and set the build environment as JAVA_1_7. And i check the File.java it doesn't shows the method toPath method in File.java
The groupid
for your artifact in Maven seems to be com.github.kenglxn.QRGen
. I know this is a minor thing but it took me some time to realize since in your documentation you state it as com.github.kenglxn.qrgen
.
Try to use your library in my project.
build.gradle:
dependencies {
....
compile 'com.github.kenglxn.QRGbuen:android:2.1.0'
....
}
When I buil my project I get error:
Error:Could not GET 'https://jitpack.io/com/github/kenglxn/QRGbuen/android/2.1.0/android-2.1.0.pom'. Received status code 401 from server: Repo not found or no access token provided
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!
I got a problem when I used two libraries of QR-Code (Ready and Generator QR-Code) in gradle
compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:1.0.0'
compile 'com.github.kenglxn.QRGen:android:2.1.0'
=================== Gradle ===============
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:1.0.0'
compile 'com.github.kenglxn.QRGen:android:2.1.0'
}
========== Message after run project failed ===============
FAILURE: Build failed with an exception.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/zxing/BarcodeFormat.class
Please fix this issue
Hello,
Is it possible to remove the border created around the QRCode or change its size?
I can always crop it or manipulate the bitmap, but it would be nice to have a lib's method to do so.
Thanks.
ps: I'm using it for Android.
The issue explained in http://stackoverflow.com/questions/26049329/javadoc-in-jdk-8-invalid-self-closing-element-not-allowed appears also in AbstractQRCode.java:17 when building with JDK 8
Update this line
QRCode.from("Hello World").to(ImageType.PNG).writeTo(outputStream);
to
QRCode.from("Hello World").to(ImageType.PNG).writeTo(stream);
because outputStream was never created.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.