alexzhirkevich/custom-qr-generator

Gradient background

donatkajtazi opened this issue · 4 comments

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

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))

Is that what you need, @donatkajtazi?

Is that what you need, @donatkajtazi?

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

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