Exemplo n.º 1
0
        /// <summary>
        /// Construct QrCode geometry. It will only include geometry for Dark colour module
        /// </summary>
        /// <returns>QrCode dark colour module geometry. Size = QrMatrix width x width</returns>
        public StreamGeometry DrawGeometry(BitMatrix QrMatrix, int offsetX, int offSetY)
        {
            int width = QrMatrix == null ? 21 : QrMatrix.Width;

            StreamGeometry qrCodeStream = new StreamGeometry();

            qrCodeStream.FillRule = FillRule.EvenOdd;

            if (QrMatrix == null)
            {
                return(qrCodeStream);
            }

            using (StreamGeometryContext qrCodeCtx = qrCodeStream.Open())
            {
                int preX = -1;

                for (int y = 0; y < width; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        if (QrMatrix[x, y])
                        {
                            //Set start point if preX == -1
                            if (preX == -1)
                            {
                                preX = x;
                            }
                            //If this is last module in that row. Draw rectangle
                            if (x == width - 1)
                            {
                                qrCodeCtx.DrawRectGeometry(new Int32Rect(preX + offsetX, y + offSetY, x - preX + 1, 1));
                                preX = -1;
                            }
                        }
                        else if (!QrMatrix[x, y] && preX != -1)
                        {
                            //Here will be first light module after sequence of dark module.
                            //Draw previews sequence of dark Module
                            qrCodeCtx.DrawRectGeometry(new Int32Rect(preX + offsetX, y + offSetY, x - preX, 1));
                            preX = -1;
                        }
                    }
                }
            }
            qrCodeStream.Freeze();

            return(qrCodeStream);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 以矩形来填充矩阵点
        /// </summary>
        /// <param name="QrMatrix">算出来的矩阵</param>
        /// <param name="xScale">isRandom?随机取值的最小值:每个点的宽度</param>
        /// <param name="yScale">isRandom?随机取值的最大值:每个点的高度</param>
        /// <param name="isRandom">是否随机大小</param>
        /// <returns>返回路径填充材质</returns>
        public static StreamGeometry DrawRectGeometry(BitMatrix QrMatrix, double xScale, double yScale, bool isRandom)
        {
            int width = QrMatrix == null ? 21 : QrMatrix.Width;

            StreamGeometry qrCodeStream = new StreamGeometry();

            qrCodeStream.FillRule = FillRule.EvenOdd;

            if (QrMatrix == null)
            {
                return(qrCodeStream);
            }


            using (StreamGeometryContext qrCodeCtx = qrCodeStream.Open())
            {
                for (int y = 0; y < width; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        if (QrMatrix[x, y])
                        {
                            if (isRandom)
                            {
                                qrCodeCtx.DrawRectGeometry(x, y, (double)(new Random(x + y + Environment.TickCount).Next((int)(xScale * 100), (int)(yScale * 100))) / 100, (double)(new Random(x + y + Environment.TickCount).Next((int)(xScale * 100), (int)(yScale * 100))) / 100);
                            }
                            else
                            {
                                qrCodeCtx.DrawRectGeometry(x, y, xScale, yScale);
                            }
                        }
                    }
                }
            }

            qrCodeStream.Freeze();

            return(qrCodeStream);
        }
Exemplo n.º 3
0
        private GeometryDrawing ConstructQZDrawing(int width)
        {
            StreamGeometry quietZoneSG = new StreamGeometry();

            quietZoneSG.FillRule = FillRule.EvenOdd;

            using (StreamGeometryContext qrCodeCtx = quietZoneSG.Open())
            {
                qrCodeCtx.DrawRectGeometry(new Int32Rect(0, 0, width, width));
            }
            quietZoneSG.Freeze();

            GeometryDrawing quietZoneDrawing = new GeometryDrawing();

            quietZoneDrawing.Brush    = m_LightBrush;
            quietZoneDrawing.Geometry = quietZoneSG;

            return(quietZoneDrawing);
        }