Ejemplo n.º 1
0
        private Image CreateQRCode(AC.Pattern pattern, int scale)
        {
            ZXing.BarcodeWriter writer = new ZXing.BarcodeWriter();
            writer.Format = ZXing.BarcodeFormat.QR_CODE;

            string data = new string(pattern.GetRawData().Select(b => Convert.ToChar(b)).ToArray());
            ZXing.Common.BitMatrix matrix = writer.Encode(data);

            Bitmap result = new Bitmap(matrix.Width * scale, matrix.Height * scale);

            // This is probably better done with LockBits. Meh.
            for (int x = 0; x < matrix.Height; x++)
                for (int y = 0; y < matrix.Width; y++)
                {
                    Color pixel = matrix[x, y] ? Color.Black : Color.White;
                    for (int i = 0; i < scale; i++)
                        for (int j = 0; j < scale; j++)
                            result.SetPixel(x * scale + i, y * scale + j, pixel);
                }

            return result;
        }