コード例 #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();
            }
        }