SkiaSharp.QrCode icon indicating copy to clipboard operation
SkiaSharp.QrCode copied to clipboard

Add information qr

Open josegerar opened this issue 3 years ago • 0 comments

I would like you to add an extension to write information to the qr code. Here is an example of what it would look like

public static void Render(this SKCanvas canvas, QRCodeData data, int width, int hight, SKColor clearColor, SKColor codeColor, IconData iconData, string iconInfo)
        {
            var hightInconInfo = 25;
            canvas.Clear(clearColor);
            using QRCodeRenderer qRCodeRenderer = new QRCodeRenderer();
            SKRect area = SKRect.Create(0f, 0f, width, hight + hightInconInfo);
            qRCodeRenderer.Render(canvas, area, data, codeColor, null, iconData);

            var fontInitNumber = 35;

            // draw some text
            var paint = new SKPaint
            {
                Color = SKColors.Black,
                IsAntialias = true,
                Style = SKPaintStyle.Fill,
                TextAlign = SKTextAlign.Center,
                TextSize = fontInitNumber
            };

            float widthicon = width / 100f * (float)iconData.IconSizePercent;
            float heigthicon = hight / 100f * (float)iconData.IconSizePercent;
            float xicon = width / 2f - widthicon / 2f;
            float yicon = hight / 2f - heigthicon / 2f;

            var dimText = paint.MeasureText(iconInfo);

            while (dimText > widthicon)
            {
                paint.TextSize = fontInitNumber--;
                dimText = paint.MeasureText(iconInfo);
            }

            var coord = new SKPoint(xicon + (dimText / 2f) + ((widthicon - dimText) / 2f), yicon + heigthicon + 10f);
            canvas.DrawText(iconInfo, coord, paint);
        }
![descargar](https://user-images.githubusercontent.com/45176268/177049680-d0997d0e-9594-48ea-9c9c-654a0877217c.png)

josegerar avatar Jul 03 '22 16:07 josegerar