alexzhirkevich / custom-qr-generator

Android library for creating QR codes with logo, custom shapes, colors, background image. Powered by ZXing
MIT License
173 stars 18 forks source link

Gradient background #7

Closed donatkajtazi closed 1 year ago

donatkajtazi commented 1 year ago

Is there a way that we can make a gradient background that fills the whole qr

alexzhirkevich commented 1 year ago

Is there a way that we can make a gradient background that fills the whole qr

For Bitmap QR code you can just set background color to gradient in options:

val options = createQrOptions(1024) {
    background {
        color = QrColor.LinearGradient(
            android.graphics.Color.RED, android.graphics.Color.BLUE,
            QrColor.LinearGradient.Orientation.LeftDiagonal
        )
    }
}

For Drawable QR code you can do it like that:

  val gradientDrawable = GradientDrawable(
      GradientDrawable.Orientation.TL_BR,
      intArrayOf(android.graphics.Color.RED, android.graphics.Color.BLUE)
  )
  val codeDrawable = QrCodeDrawable(context, data, anyOptions)

  val codeWithGradientBg = LayerDrawable(arrayOf(gradientDrawable, codeDrawable))
alexzhirkevich commented 1 year ago

Is that what you need, @donatkajtazi?

donatkajtazi commented 1 year ago

Is that what you need, @donatkajtazi?

looks like it was there all along I just didn't find it

alexzhirkevich commented 1 year ago

Background image and color for Drawable codes (without LayerDrawable) will be supported in the next update (1.5.3)