public void generateTable(Image img, Table tbl) { Tree tree = BuildQuadtree (img); // Create initial row and cell. TableRow tbr = new TableRow(); TableData tbd = new TableData(); tbr.Cells.Add(tbd); tbl.Rows.Add(tbr); // Generate into cell. recursivelyGenerateTable(tree.RootNode, tbd); }
public void generateTable(Image img, Table tbl) { // Downsample image. int newHeight = (img.Size.Height / this.mSize) + 1; int newWidth = (img.Size.Width / this.mSize) + 1; Bitmap newImg = new Bitmap(newWidth, newHeight); using (Graphics g = Graphics.FromImage (newImg)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; g.DrawImage(img, new Rectangle(0, 0, newWidth, newHeight)); } // Now iterate over down-sampled image to generate mosaic. for (int y = 0; y < newHeight; ++y) { TableRow tbr = new TableRow(); tbl.Rows.Add (tbr); for(int x = 0; x < newWidth; ++x) { TableData tbd = new TableData(); tbd.BackgroundColour = newImg.GetPixel (x, y); tbd.Height = this.Size; tbd.Width = this.Size; tbd.ChildElement = null; tbr.Cells.Add(tbd); } } }
private void recursivelyGenerateTable(Node current, TableData tbd) { if (current.IsLeaf == false) { // If not a leaf, introduce a nested table. Table tbl = new Table(); tbl.BackgroundColour = tbd.BackgroundColour; tbd.ChildElement = tbl; // Add children to this nested table in NW, NE, SW, SE order. TableRow tbr = null; for (int i = 0; i < 4; ++i) { if (i % 2 == 0) { tbr = new TableRow(); tbl.Rows.Add(tbr); } TableData tbdd = new TableData(); tbr.Cells.Add(tbdd); recursivelyGenerateTable(current.ChildNodes[i], tbdd); } } else { // If a leaf, simply set the colour on the current element. tbd.BackgroundColour = current.Colour; tbd.Height = current.Height; tbd.Width = current.Width; tbd.ColumnSpan = 1; } }
public void visit(TableRow element) { // Now have a straight set of column runs. mStringBuilder.Append ("<tr>"); foreach(TableData cell in element.Cells) { cell.accept (this); } mStringBuilder.Append ("</tr>"); }