示例#1
0
        private static void AppendDarkCell(SvgImage image, BitMatrix matrix, int offsetX, int offSetY)
        {
            if (matrix == null)
            {
                return;
            }

            int  width          = matrix.Width;
            int  height         = matrix.Height;
            var  processed      = new BitMatrix(width, height);
            bool currentIsBlack = false;
            int  startPosX      = 0;
            int  startPosY      = 0;

            for (int x = 0; x < width; x++)
            {
                int endPosX;
                for (int y = 0; y < height; y++)
                {
                    if (processed[x, y])
                    {
                        continue;
                    }

                    processed[x, y] = true;

                    if (matrix[x, y])
                    {
                        if (!currentIsBlack)
                        {
                            startPosX      = x;
                            startPosY      = y;
                            currentIsBlack = true;
                        }
                    }
                    else
                    {
                        if (currentIsBlack)
                        {
                            FindMaximumRectangle(matrix, processed, startPosX, startPosY, y, out endPosX);
                            image.AddRec(startPosX + offsetX, startPosY + offSetY, endPosX - startPosX + 1, y - startPosY);
                            currentIsBlack = false;
                        }
                    }
                }
                if (currentIsBlack)
                {
                    FindMaximumRectangle(matrix, processed, startPosX, startPosY, height, out endPosX);
                    image.AddRec(startPosX + offsetX, startPosY + offSetY, endPosX - startPosX + 1, height - startPosY);
                    currentIsBlack = false;
                }
            }
        }