Exemple #1
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 DrawEllipseGeometry(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.DrawEllipseGeometry(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.DrawEllipseGeometry(x, y, xScale, yScale);
                            }
                        }
                    }
                }
            }


            qrCodeStream.Freeze();

            return(qrCodeStream);
        }