QRGen 一个灵活简单的java 二维码生成jar 包

QRGen 是基于ZXing 包装的一个二维码生成jar包,使用简单(一行代码搞定二维码)

使用

  • 引用包
  <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
 <dependencies>
        <dependency>
            <groupId>com.github.kenglxn.qrgen</groupId>
            <artifactId>javase</artifactId>
            <version>2.6.0</version>
        </dependency>
    </dependencies> 
  • 代码使用
    代码来自官方文档,但是简单生成就是一行代码搞定
 
// 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("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("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("john.doe@example.org");
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

参考资料

https://github.com/kenglxn/QRGen

posted on   荣锋亮  阅读(756)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-09-29 Cortex Architecture
2019-09-29 cortex 水平扩展试用
2019-09-29 cortex 基本试用
2019-09-29 10 Unit Testing and Automation Tools and Libraries Java Programmers Should Learn
2018-09-29 nuclio kubernetes 部署
2018-09-29 nuclio dokcer 运行测试

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示