Exemplo n.º 1
0
        Image CreatePreviewImage(XmlNode dataNode)
        {
            int height   = 240;
            int width    = 530;
            int diameter = 40;

            Bitmap   bmp = new Bitmap(width, height);
            Graphics g   = Graphics.FromImage(bmp);

            BiTreeGenerator biTreeGenerator = new BiTreeGenerator();

            biTreeGenerator.DataNode  = dataNode;
            biTreeGenerator.IsPreview = true;
            biTreeGenerator.GenerateTree(diameter, Color.HotPink);
            //注意:这里我还是使用先序遍历,因为用什么遍历方法无很大关系,关键是最终的结果要正确
            IIterator preOrderTreeIterator  = new BiTreePreOrderIterator(biTreeGenerator.RootNode);
            IIterator preOrderTreeIterator1 = new BiTreePreOrderIterator(biTreeGenerator.RootLineNode);

            if (preOrderTreeIterator != null)
            {
                for (IIterator iterator = preOrderTreeIterator.First(); !preOrderTreeIterator.IsDone(); iterator = preOrderTreeIterator.Next())
                {
                    if (iterator.CurrentItem != null)
                    {
                        iterator.CurrentItem.BackColor = Color.HotPink;
                        iterator.CurrentItem.Draw(g);
                    }
                }
            }
            if (preOrderTreeIterator1 != null)
            {
                for (IIterator iterator = preOrderTreeIterator1.First(); !preOrderTreeIterator1.IsDone(); iterator = preOrderTreeIterator1.Next())
                {
                    if (iterator.CurrentItem != null)
                    {
                        iterator.CurrentItem.Draw(g);
                    }
                }
            }

            return(bmp);
        }
Exemplo n.º 2
0
        //生成一棵二叉树,并把生成的位图返回
        Bitmap GenerateTree(bool isFullTree)
        {
            int height   = 240;
            int width    = 530;
            int diameter = 40;

            biTreeGenerator.IsFullTree = isFullTree;
            biTreeGenerator.GenerateTree1(diameter, Color.HotPink);

            Bitmap   bmp = new Bitmap(width, height);
            Graphics g   = Graphics.FromImage(bmp);

            IIterator preOrderTreeIterator  = new BiTreePreOrderIterator(biTreeGenerator.RootNode);
            IIterator preOrderTreeIterator1 = new BiTreePreOrderIterator(biTreeGenerator.RootLineNode);

            if (preOrderTreeIterator != null)
            {
                for (IIterator iterator = preOrderTreeIterator.First(); !preOrderTreeIterator.IsDone(); iterator = preOrderTreeIterator.Next())
                {
                    if (iterator.CurrentItem != null)
                    {
                        iterator.CurrentItem.BackColor = Color.HotPink;
                        iterator.CurrentItem.Draw(g);
                    }
                }
            }
            if (preOrderTreeIterator1 != null)
            {
                for (IIterator iterator = preOrderTreeIterator1.First(); !preOrderTreeIterator1.IsDone(); iterator = preOrderTreeIterator1.Next())
                {
                    if (iterator.CurrentItem != null)
                    {
                        iterator.CurrentItem.Draw(g);
                    }
                }
            }

            return(bmp);
        }