Пример #1
0
        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);
        }
Пример #2
0
        private static String GenerateHTMLForImage(Image img, IStrategy strategy)
        {
            // Create table .
            Table tbl = new Table();

            // Convert image.
            strategy.generateTable(img, tbl);

            // Table to HTML.
            HTMLBuilder builder = new HTMLBuilder();
            tbl.accept(builder);

            return builder.HTML;
        }
Пример #3
0
        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);
                }
            }
        }
Пример #4
0
        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;
            }
        }
Пример #5
0
        public void visit(Table element)
        {
            // Opening tag.
            mStringBuilder.Append ( "<table cellpadding=0 cellspacing=0");

            // Add colour if required.
            Color original = this.mCurrentBackground;
            if (element.BackgroundColour.Equals (this.mCurrentBackground) == false) {
                mStringBuilder.AppendFormat ( " bgcolor={0}",ColorTranslator.ToHtml(element.BackgroundColour));

                this.mCurrentBackground = element.BackgroundColour;
            }

            mStringBuilder .Append ( ">");

            // Generate row HTML.
            foreach(TableRow row in element.Rows) {
                row.accept (this);
            }

            // Closing tag.
            mStringBuilder.Append ("</table>");

            // Reset background colour.
            this.mCurrentBackground = original;
        }