//gridLines[areaX][areaY][direction(x=0,y=1)][EachLines]
        internal virtual bool[][] getQRCodeMatrix(bool[][] image, SamplingGrid gridLines)
        {
            //int gridSize = gridLines.getWidth() * gridLines.getWidth(0,0);
            int gridSize = gridLines.TotalWidth;

            // now this is done within the SamplingGrid class...
            //		if (gridLines.getWidth() >= 2)
            //			gridSize-=1;

            canvas.println("gridSize=" + gridSize);
            //canvas.println("gridLines.getWidth() * gridLines.getWidth(0,0) = "+gridLines.getWidth() * gridLines.getWidth(0,0));
            Point bottomRightPoint = null;
            bool[][] sampledMatrix = new bool[gridSize][];
            for (int i = 0; i < gridSize; i++)
            {
                sampledMatrix[i] = new bool[gridSize];
            }
            for (int ay = 0; ay < gridLines.getHeight(); ay++)
            {
                for (int ax = 0; ax < gridLines.getWidth(); ax++)
                {
                    System.Collections.ArrayList sampledPoints = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); //only for visualiz;
                    for (int y = 0; y < gridLines.getHeight(ax, ay); y++)
                    {
                        for (int x = 0; x < gridLines.getWidth(ax, ay); x++)
                        {
                            int x1 = gridLines.getXLine(ax, ay, x).getP1().X;
                            int y1 = gridLines.getXLine(ax, ay, x).getP1().Y;
                            int x2 = gridLines.getXLine(ax, ay, x).getP2().X;
                            int y2 = gridLines.getXLine(ax, ay, x).getP2().Y;
                            int x3 = gridLines.getYLine(ax, ay, y).getP1().X;
                            int y3 = gridLines.getYLine(ax, ay, y).getP1().Y;
                            int x4 = gridLines.getYLine(ax, ay, y).getP2().X;
                            int y4 = gridLines.getYLine(ax, ay, y).getP2().Y;

                            int e = (y2 - y1) * (x3 - x4) - (y4 - y3) * (x1 - x2);
                            int f = (x1 * y2 - x2 * y1) * (x3 - x4) - (x3 * y4 - x4 * y3) * (x1 - x2);
                            int g = (x3 * y4 - x4 * y3) * (y2 - y1) - (x1 * y2 - x2 * y1) * (y4 - y3);
                            sampledMatrix[gridLines.getX(ax, x)][gridLines.getY(ay, y)] = image[f / e][g / e];
                            if ((ay == gridLines.getHeight() - 1 && ax == gridLines.getWidth() - 1) && y == gridLines.getHeight(ax, ay) - 1 && x == gridLines.getWidth(ax, ay) - 1)
                                bottomRightPoint = new Point(f / e, g / e);
                            //calling canvas.drawPoint in loop can be very slow.
                            // use canvas.drawPoints if you need
                            //canvas.drawPoint(new Point(f / e,g / e), Color.RED);
                        }
                    }
                }
            }
            if (bottomRightPoint.X > image.Length - 1 || bottomRightPoint.Y > image[0].Length - 1)
                throw new System.IndexOutOfRangeException("Sampling grid pointed out of image");
            canvas.drawPoint(bottomRightPoint, MessagingToolkit.QRCode.Codec.Util.Color_Fields.BLUE);

            return sampledMatrix;
        }