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

Overview

custom-qr-generator

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

Installation

To get a Git project into your build:

Step 1. Add the JitPack repository to your build file

allprojects {
    repositories {
      ...
        maven { url 'https://jitpack.io' }
    }
}

Or for gradle 7+ to settings.gradle file:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        ...
        maven {
            url 'https://jitpack.io'        
        }
    }
}

Step 2. Add the dependency.

dependencies {
    implementation 'com.github.alexzhirkevich:custom-qr-generator:1.2.0'
}

Usage

Step 1. Create QR code data. There are multiple QR types support: Plain Text, Url, Wi-Fi, Email, GeoPos, Profile Cards, Phone, etc.

val data = QrData.Url("https://example.com")

Step 2. Define styling options:

val options = QrOptions.Builder(1024)
    .setPadding(.3f)
    .setBackground(
        QrBackgroundImage(
            drawable = ContextCompat
                .getDrawable(this, R.drawable.frame)!!,
        )
    )
    .setLogo(
        QrLogo(
            drawable = ContextCompat
                .getDrawable(this, R.drawable.tg)!!,
            size = .2f,
            padding = .2f,
            shape = QrLogoShape
                .Circle
        )
    )
    .setColors(
        QrColors(
            dark = QrColor
                .Solid(Color.parseColor("#345288")),
            bitmapBackground = QrColor.Solid(Color.WHITE),
            codeBackground = QrColor
                .Solid(Color.parseColor("#ddffffff")),
        )
    )
    .setElementsShapes(
        QrElementsShapes(
            darkPixel = QrPixelShape
                .RoundCorners(),
            ball = QrBallShape
                .RoundCorners(.25f),
            frame = QrFrameShape
                .RoundCorners(.25f),
            background = QrBackgroundShape
                .RoundCorners(.05f)
        )
    )
    .build()

Step 2. Create a QR code generator and pass your data and options into it:

val generator: QrCodeGenerator = QrGenerator()
  
val bitmap = generator.generateQrCode(data, options)

It is better to perform QR codes generating in background thread. Generator supports cancellation with coroutines.

val bitmap = generator.generateQrCodeSuspend(data, options)

Customization

You can easily implement your own shapes and coloring for QR Code elements using math formulas. For example, this is implementation of Circle QR-pixels:

object Circle : QrPixelShape {
    override fun invoke(
        i: Int, j: Int, elementSize: Int,
        qrPixelSize: Int, neighbors: Neighbors
    ): Boolean = {
        val center = elementSize/2.0
        return (sqrt((center-i)*(center-i) + (center-j)*(center-j)) < center)
    }
}
Comments
  • Flutter support

    Flutter support

    Hi Alex,

    Thanks for this amazing example project, can you add support for Flutter for Custom Qr Generator? I think will be amazing for pub.dev community!

    Thanks in advance!

    enhancement help wanted 
    opened by RoyalCoder88 14
  • Error if set logo

    Error if set logo

    If i set logo from DrawableSource.Resource it crash my app, if i set DrawableSource.Empty all ok I convert drawable to bitmap and it throw me error if i set logo Logs: java.lang.IllegalArgumentException: width and height must be > 0 at android.graphics.Bitmap.createBitmap(Bitmap.java:1111) at android.graphics.Bitmap.createBitmap(Bitmap.java:1078) at android.graphics.Bitmap.createBitmap(Bitmap.java:1028) at android.graphics.Bitmap.createBitmap(Bitmap.java:989) at androidx.core.graphics.drawable.DrawableKt.toBitmap(Drawable.kt:68) at com.github.alexzhirkevich.customqrgenerator.style.BitmapScale$FitXY.scale(BitmapScale.kt:33) at com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawableImpl.resize(QrCodeDrawableImpl.kt:369) at com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawableImpl.setBounds(QrCodeDrawableImpl.kt:128) at androidx.core.graphics.drawable.DrawableKt.toBitmap(Drawable.kt:72) at androidx.core.graphics.drawable.DrawableKt.toBitmap$default(Drawable.kt:46)

    Code(Jetpack Compose used): val data = QrData.Text(curSchedule?.JoinCode.toString()) val options = QrVectorOptions.Builder() .setPadding(.3f) .setErrorCorrectionLevel(QrErrorCorrectionLevel.High) .setLogo( QrVectorLogo( drawable =drawable, ) ) .setShapes( QrVectorShapes( darkPixel = QrVectorPixelShape .RoundCorners(.5f), ball = QrVectorBallShape .RoundCorners(.25f), frame = QrVectorFrameShape .RoundCorners(.25f), ) ) .build() val drawable = QrCodeDrawable(context, data, options) Image( bitmap = drawable.toBitmap(1024, 1024).asImageBitmap(), contentDescription = "qrCode", modifier = Modifier .fillMaxSize() )

    opened by BadKiko 8
  • Ambiguous method call

    Ambiguous method call

    It is not possible to use QrVectorOptions.Builder from java side. Decompiler shows identical setters for all fields inside builder. qrcg_issue

    version used: 1.5.3

    bug 
    opened by ruinalgo 2
  • Incorrect coding Cyrillic letters

    Incorrect coding Cyrillic letters

    When I generate a VCard QR code with a name in Cyrillic letters, when I scan the code, the name "Роман" became "?????", but if I set the name as "Roman", the code works correctly

    opened by krauzee 2
  • crash

    crash

    2022-07-29 10:18:21.322 16256-16256/com.github.alexzhirkevich.customqrgenerator.example E/AndroidRuntime: FATAL EXCEPTION: main Process: com.github.alexzhirkevich.customqrgenerator.example, PID: 16256 com.github.alexzhirkevich.customqrgenerator.QrCodeCreationException at com.github.alexzhirkevich.customqrgenerator.QrGenerator$generateQrCodeSuspend$2.invokeSuspend(QRGenerator.kt:38) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@7ecff62, Dispatchers.Main.immediate] Caused by: java.lang.NoSuchMethodError: No static method pack(I)J in class Landroid/graphics/Color; or its super classes (declaration of 'android.graphics.Color' appears in /system/framework/framework.jar) at com.github.alexzhirkevich.customqrgenerator.QrGenerator.drawBackground(QRGenerator.kt:231) at com.github.alexzhirkevich.customqrgenerator.QrGenerator.createQrCodeInternal(QRGenerator.kt:53) at com.github.alexzhirkevich.customqrgenerator.QrGenerator.access$createQrCodeInternal(QRGenerator.kt:16) at com.github.alexzhirkevich.customqrgenerator.QrGenerator$generateQrCodeSuspend$2$1$1.invokeSuspend(QRGenerator.kt:33) at com.github.alexzhirkevich.customqrgenerator.QrGenerator$generateQrCodeSuspend$2$1$1.invoke(QRGenerator.kt) at com.github.alexzhirkevich.customqrgenerator.QrGenerator$generateQrCodeSuspend$2$1$1.invoke(QRGenerator.kt) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89) at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264) at com.github.alexzhirkevich.customqrgenerator.QrGenerator$generateQrCodeSuspend$2.invokeSuspend(QRGenerator.kt:32)

    invalid 
    opened by maratkarelov 0
Releases(1.5.4)
  • 1.5.4(Dec 23, 2022)

    • Changed naming conventions in QrOptions.Builder and QrVectorOptions.Builder to be compatible with java
    • Fixed crash caused by setBounds with zero size.
    Source code(tar.gz)
    Source code(zip)
  • 1.5.3(Nov 26, 2022)

  • 1.5.2(Nov 19, 2022)

    Vector codes update

    • Added support for different logo paddings (as in raster codes)
    • Added more default shapes for each shape types
    • Added ability to change code shape (as in raster codes)
    • Fixed bug with incorrect logo offset when using QR code padding

    Added ability to create custom shapes for raster codes with android.graphics.Path using pathShape in DSL QrOptions build. drawShape is deprecated

    Source code(tar.gz)
    Source code(zip)
  • 1.5.1(Oct 22, 2022)

  • 1.5.0(Oct 5, 2022)

  • 1.4.1(Sep 2, 2022)

    What's new:

    • New colouring ability for pixels - QrColorSeparatePixels. Allows to paint each QR code pixels in separate solid colour.
    • Added stability tests

    Fixed bugs:

    • Fixed crash when using custom ball and frame shapes
    Source code(tar.gz)
    Source code(zip)
  • 1.4.0(Aug 29, 2022)

    What's new:

    • New gradient colour - RhombusGradient. Looks like SquareGradient, but rotated by 45 degree;
    • New QrOptions parameter - QrOffset. Now QR code pattern can have x and y offset;
    • Added serialization ability. Now QrOptions, QrData or any class from style package can be serialized using kotlinx-serialization. All options and QrData classes marked as @Serializable. Every class with interface preperties (or interfaces itself) now have companion object with defaultSerializersModule property. It provides kotlinx-serialization SerializersModule that should be used to serialize it instances. There is global value QrSerializersModule, that can be used to serialize any serializable class instance. [!] If you implemented custom shape, color or other option, it must be added to module. Serialization can be useful for remote config QR code style changing or to store generated codes with their options for later modification (for ex, in QR code generator apps)

    Changes:

    • Reworked DSL. Parameter instantiationing replaced with corresponding builder functions with own scopes. Canvas shape and colour builders moved from top-level QrOptionBuilderScope to corresponding 2nd-level scopes.
    • drawShapeModifier renamed to 'drawShape`
    • QrCanvasShapeModifier renamed to QrCanvasShape;
    • QrBackgroundImage renamed to QrBackground;
    • QrBackgroundColor moved from QrColors to QrBackground;
    • QrLogo and QrBackground drawable parameter changed from Drawable to wrapper - DrawableSource; It can be Empty, Resource, File. Custom DrawableSource can be implemented (for example web source). It made due to serialization needs and to simplify drawable picking from file system. It automatically disables mutability flag from picked image (mutable bitmaps cause exception);
    • QrCodeGenerator instance must now be created using QrCodeGenerator function (same name). Now it requires Context. Old QrGenerator class is now internal and renamed to QrCodeGeneratorImpl;
    • Reworked options size parameter. size -> width & height. Now width can be unequal to height (does not affect QR code pattern, it is still square). With new QrOffset parameter, it can be useful for non-square backgrounds (for example, frame with "SCAN ME" label below)

    Fixed bugs:

    • Fixed image blending bugs. Visual glitches could occur if your background or logo image had partially transparent pixels.
    • Fixed RadialGradient. Now it is true radial. Radius can be > 1
    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Aug 13, 2022)

    New features:

    • Added DSL QrOptions builder - createQrOptions
    • Added ablity to create custom elements shapes by drawing on canvas (implement QrCanvasShapeModifier and convert it to necessary shape or use drawElementShape function inside DSL build)
    • Added ablity to create custom QrColor by drawing on canvas (implement QrCanvasColor or use draw function inside DSL build)
    • Added BitmapScale for QrLogo and QrBackgroundImage. You can now CenterCrop your drawable instead of resizing it to square
    • Changed logo padding API. Now it is separate class QrLogoPadding. It now can be Empty, Accurate (like before) or Natural (accurate, but all cropped pixels are removed)
    • Added new gradient color type - SquareGradient. Looks like RadialGradient but with square shape

    Shapes:

    • Optimized default shapes
    • Reworked some default shapes
    • Added new default shape - QrPixelShape.Star

    Bugfix:

    • Fixed gradient colors for QR pixels. Now it is properly centered.
    • Fixed RadialGradient radius. Now it is bigger.
    • Fixed ball and frame color incorrect draw position
    Source code(tar.gz)
    Source code(zip)
  • 1.2.5(Aug 1, 2022)

  • 1.2.3(Jul 1, 2022)

  • 1.2.2(Jun 23, 2022)

  • 1.2.0(Jun 21, 2022)

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

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

王浩 7.7k Dec 29, 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
a simple QRCode generation api for java built on top ZXING

QRGen: a simple QRCode generation api for java built on top ZXING Please consider sponsoring the work on QRGen Dependencies: ZXING: http://code.google

Ken Gullaksen 1.4k Dec 31, 2022
ZATAC Scanner is Android Kotlin-based QR code scanner and parser which de-crypt TLV qr codes and parse them into their values.

ZATAC Scanner is Android Kotlin-based QR code scanner and parser which de-crypt TLV qr codes and parse them into their values.

Enozom 12 Apr 23, 2022
Android app and Python library for turning mobile phone into a WebSocket-based, remotely controllable Barcode/QR code reader

Remote Barcode Reader suite Android app and Python library for turning mobile phone into a remotely controllable Barcode/QR code reader. It exposes a

Krystian Dużyński 3 Dec 6, 2022
A library to help implement barcode scanning

A library to help implement barcode scanning

Brightec 99 Nov 30, 2022
Barcode Scanner Libraries for Android

Project Archived July 1 2020 This project is no longer maintained. When I first started this project in late 2013 there were very few libraries to hel

Dushyanth 5.4k Jan 3, 2023
Qart is Android App that's based on CuteR project. App generate QR code that merge a picture. So the QR code looks more beautiful.

Qart is Android App that's based on CuteR project. App generate QR code that merge a picture. So the QR code looks more beautiful.

scola 1k Dec 16, 2022
QRAlarm - an Android alarm clock application lets the user turn off alarms by scanning the QR Code.

QRAlarm is an Android alarm clock application that does not only wake You up, but also makes You get up to disable the alarm by scanning the QR Code.

null 39 Jan 8, 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
Pixel Launcher Mods a root app for Android 12+ that enables you to add a number of features to the stock Pixel Launcher

A root app that enables you to add a number of features to the stock Pixel Launcher, without needing Xposed

Kieron Quinn 430 Jan 2, 2023
Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling Scale Image View, Fresco, Glide, and Picasso. Even with gif and webp support! 🍻

BigImageViewer Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling

Piasy 3.9k Dec 30, 2022
Secret Codes is an Open Source application that allows you to browse through hidden codes of your Android phone.

####Secret Codes is an Open Source application that allows you to browse through hidden codes of your Android phone. This application will scan throug

Simon Marquis 251 Jan 6, 2023
Android fillable progress view working with SVG paths. This is a nice option too if you want to create an interesting branding logo for your app. Based on the iOS project: https://github.com/poolqf/FillableLoaders

Android FillableLoaders Android Open Source library providing an interesting fillable progress view working with SVG paths. This is a nice option too

Jorge Castillo 2k Jan 1, 2023
🖼 Supports loading profile images with segmented style, shapes, borders, indicators, and initials for Android.

AvatarView AvatarView supports loading profile images with segmented style, borders, indicators, and initials for Android. Download Gradle Add the bel

Stream 395 Dec 22, 2022
Android AccessibilityService that performs gestures on behalf of the user whenever they blink their eyes.

BlinkScroll An Android Accessibility Service that monitors a user's face via the phone's front-facing camera. When the user blinks (or winks), the ser

Guy Dupont 2 Sep 28, 2022
VideoView that plays video only when :eyes: are open and :boy: is detected with various other features

LookAtMe VideoView that plays video only when ?? are open and ?? is detected with various other features GIF AndroidPub (Medium) Post You can read the

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

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

王浩 7.7k Dec 29, 2022
Group Messaging Chat (Discord Clone :eyes:) App Using Firebase Cloud-Firestore following MVVM Architecture

Nit Talk Nit Talk is a Group Chat Messaging (Discord Clone) App based on Modern Android Application tech-stacks and MVVM architecture. Techs Used ?? K

Rohit Sharma 27 Jul 22, 2022
Drawing App: A simple drawing application that allows the user to draw using a pencil or using shapes

Drawing-App Drawing app is a simple drawing application that allows the user to

Nada Feteiha 1 Oct 5, 2022