예제 #1
0
파일: RTree.cs 프로젝트: kai-liki/Study
        public RTree(PixelMatrix pm, RNode rt, byte tr, byte tg, byte tb, int dr, int dg, int db, int dx)
        {
            if (rt != null && pm != null)
            {
                this.pm = pm;
                this.root = rt;
                r = tr;
                g = tg;
                b = tb;
                diffR = dr;
                diffG = dg;
                diffB = db;
                diffX = dx;

                GetBranches(this.root);
            }
            else
            {
                throw new NullReferenceException();
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: kai-liki/Study
        private void button4_Click(object sender, EventArgs e)
        {
            r = byte.Parse(labelR.Text);
            g = byte.Parse(labelG.Text);
            b = byte.Parse(labelB.Text);
            diffR = (int)numericUpDownR.Value;
            diffG = (int)numericUpDownG.Value;
            diffB = (int)numericUpDownB.Value;
            diffX = (int)numericUpDownX.Value;
            if (pictureBox1.Image != null)
            {
                Bitmap bmp = new Bitmap(pictureBox1.Image);
                Bitmap tbmp = new Bitmap(bmp.Width, bmp.Height);
                PixelMatrix matrix = new PixelMatrix(bmp.Width, bmp.Height);
                for (int x = 0; x < bmp.Width; x++)
                {
                    for (int y = 0; y < bmp.Height; y++)
                    {
                        Color c = bmp.GetPixel(x, y);
                        RNode node = new RNode();
                        node.R = c.R;
                        node.G = c.G;
                        node.B = c.B;
                        node.x = x;
                        node.y = y;
                        matrix.nodes[x, y] = node;
                    }
                }

                RTree.Verify += new VerifyDelegate(VerifyRGB);

                List<RTree> rtrees = new List<RTree>();

                for (int x = 0; x < bmp.Width; x++)
                {
                    for (int y = 0; y < bmp.Height; y++)
                    {
                        RNode node = matrix.nodes[x, y];
                        if (!node.reached)
                        {
                            if (RTree.Verify(node.R, node.G, node.B, r, g, b, diffR, diffG, diffB))
                            {
                                RTree rtree = new RTree(matrix, node, r, g, b, diffR, diffG, diffB, diffX);
                                rtrees.Add(rtree);
                            }

                        }
                    }
                }

                foreach (RTree rt in rtrees)
                {
                    rt.DrawNodes(rt.root, tbmp);
                }

                pictureBox4.Image = tbmp;
                rtrees.Clear();
            }
        }