Giter VIP home page Giter VIP logo

Comments (8)

alexzhirkevich avatar alexzhirkevich commented on June 3, 2024

You can do

val options = createQrVectorOptions {
    colors {
        dark = QrVectorColor.Eraser
    }
    background {
        color = QrVectorColor.Solid(Color.WHITE)
    }
}

This will create drawable where QRcode is cut from white background. Then you can place this drawable above any other View and this view will be visible throught the holes

Or you can merge your image and this drawable using

val resultDrawable  = LayerDrawable(arrayOf(imageDrawable, qrCodeDrawable))

from custom-qr-generator.

alexzhirkevich avatar alexzhirkevich commented on June 3, 2024

Or you can use this to just cut QR code from your provided imageDrawable

val options = createQrVectorOptions {
    colors {
        light = QrVectorColor.Eraser
        dark = QrVectorColor.Transparent
    }
    background {
        drawable = imageDrawable
    }
}

from custom-qr-generator.

chuongdk2011 avatar chuongdk2011 commented on June 3, 2024

I tried the above codes, but my idea is to overlay the image on the places where the QrCode is, like set a color for the QrCode, and the remaining parts that don't have the Qrcode will show up in the default background color.

from custom-qr-generator.

chuongdk2011 avatar chuongdk2011 commented on June 3, 2024

It seems your code above is doing the opposite.

from custom-qr-generator.

alexzhirkevich avatar alexzhirkevich commented on June 3, 2024

You can create custom QrVectorColor and make a shaderPaint using BitmapShader from your image

from custom-qr-generator.

alexzhirkevich avatar alexzhirkevich commented on June 3, 2024

Here is an example:

class QrImageColor(private val image : Drawable) : QrVectorColor {
    override fun createPaint(width: Float, height: Float): Paint {
        val bitmap = image.toBitmap(width.roundToInt(),height.roundToInt())
        val bitmapShader = BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
        return Paint().apply {
            shader = bitmapShader
        }
    }
}

from custom-qr-generator.

alexzhirkevich avatar alexzhirkevich commented on June 3, 2024

@chuongdk2011 Doest it fit your needs?

from custom-qr-generator.

chuongdk2011 avatar chuongdk2011 commented on June 3, 2024

Yes, I did it. Thank you very much

from custom-qr-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.