//qrcode-kotlin/qrcode/QRCode/renderShaded
[common]\
fun renderShaded(cellSize: Int = DEFAULT_CELL_SIZE, margin: Int = DEFAULT_MARGIN, rawData: Array<Array<QRCodeSquare?>> = encode(), qrCodeGraphics: QRCodeGraphics = qrCodeGraphicsFactory.newGraphicsSquare( computeImageSize( cellSize, margin, rawData ) ), renderer: (QRCodeSquare, QRCodeGraphics) -> Unit): QRCodeGraphics
Renders a QR Code image based on its computed data.
This function provides a way to implement more artistic QRCodes. The renderer is a function that draws a single square of the QRCode. It receives 2 parameters: cellData and a QRCodeGraphics for it to freely draw. After finished, the canvas will be placed into the final image in its respective place.
To show this, here’s a renderer that makes a QR Code that is half blue and half red:
QRCode("example").renderShaded { cellData, graphics ->
if (cellData.type != QRCodeSquareType.MARGIN && cellData.dark) {
if (cellData.row cellData.size / 2) {
graphics.fill(Colors.BLUE)
}
else {
graphics.fill(Colors.RED)
}
} else {
graphics.fill(Colors.WHITE)
}
}
Tip: for the "traditional look-and-feel" QR Code, try setting margin equal to cellSize.
A QRCodeGraphics with the QR Code rendered on it. It can then be saved or manipulated as desired.
common
cellSize | The size in pixels of each square (cell) in the QR Code. Defaults to 25 . |
margin | Amount of space in pixels to add as a margin around the rendered QR Code. Defaults to 0 . |
rawData | The data matrix of the QR Code. Defaults to this.encode(). |
qrCodeGraphics | The QRCodeGraphics where the QRCode will be painted into. |
renderer | Lambda that draws a single QRCode square. It receives as parameters the QRCodeSquare being draw and a QRCodeGraphics for it to draw the square. |
QRCodeSquare |
QRCodeGraphics |
Colors |