//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, ThoughtWorks.QRCode.Codec.Util.Color_Fields.BLUE);
			
			return sampledMatrix;
		}
示例#2
0
 internal virtual bool[][] getQRCodeMatrix(bool[][] image, SamplingGrid gridLines)
 {
     int totalWidth = gridLines.TotalWidth;
     this.canvas.println("gridSize=" + totalWidth);
     Point point = null;
     bool[][] flagArray = new bool[totalWidth][];
     for (int i = 0; i < totalWidth; i++)
     {
         flagArray[i] = new bool[totalWidth];
     }
     for (int j = 0; j < gridLines.getHeight(); j++)
     {
         for (int k = 0; k < gridLines.getWidth(); k++)
         {
             ArrayList list = ArrayList.Synchronized(new ArrayList(10));
             for (int m = 0; m < gridLines.getHeight(k, j); m++)
             {
                 for (int n = 0; n < gridLines.getWidth(k, j); n++)
                 {
                     int x = gridLines.getXLine(k, j, n).getP1().X;
                     int y = gridLines.getXLine(k, j, n).getP1().Y;
                     int num9 = gridLines.getXLine(k, j, n).getP2().X;
                     int num10 = gridLines.getXLine(k, j, n).getP2().Y;
                     int num11 = gridLines.getYLine(k, j, m).getP1().X;
                     int num12 = gridLines.getYLine(k, j, m).getP1().Y;
                     int num13 = gridLines.getYLine(k, j, m).getP2().X;
                     int num14 = gridLines.getYLine(k, j, m).getP2().Y;
                     int num15 = ((num10 - y) * (num11 - num13)) - ((num14 - num12) * (x - num9));
                     int num16 = (((x * num10) - (num9 * y)) * (num11 - num13)) - (((num11 * num14) - (num13 * num12)) * (x - num9));
                     int num17 = (((num11 * num14) - (num13 * num12)) * (num10 - y)) - (((x * num10) - (num9 * y)) * (num14 - num12));
                     flagArray[gridLines.getX(k, n)][gridLines.getY(j, m)] = image[num16 / num15][num17 / num15];
                     if ((((j == (gridLines.getHeight() - 1)) && (k == (gridLines.getWidth() - 1))) && (m == (gridLines.getHeight(k, j) - 1))) && (n == (gridLines.getWidth(k, j) - 1)))
                     {
                         point = new Point(num16 / num15, num17 / num15);
                     }
                 }
             }
         }
     }
     if ((point.X > (image.Length - 1)) || (point.Y > (image[0].Length - 1)))
     {
         throw new IndexOutOfRangeException("Sampling grid pointed out of image");
     }
     this.canvas.drawPoint(point, Color_Fields.BLUE);
     return flagArray;
 }