コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //this.Cursor = Cursor.WaitCursor;
            cc.ConvertRGBimagetoHSV();
            int width  = cc.rgbImage.Width;
            int height = cc.rgbImage.Height;

            if (this.checkBox1.Checked)
            {
                width = width / 2;
            }


            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    //тон
                    int tmpH = cc.hsvImage[i, j].h + trackBar1.Value;
                    if (tmpH < 0)
                    {
                        cc.hsvImage[i, j].h = (ushort)(tmpH + 360);
                    }
                    else if (tmpH >= 360)
                    {
                        cc.hsvImage[i, j].h = (ushort)(tmpH - 360);
                    }
                    else
                    {
                        cc.hsvImage[i, j].h = (ushort)tmpH;
                    }
                    //насыщенность
                    int tmpS = cc.hsvImage[i, j].s + trackBar2.Value;
                    if (tmpS < 0)
                    {
                        cc.hsvImage[i, j].s = 0;
                    }
                    else if (tmpS >= 100)
                    {
                        cc.hsvImage[i, j].s = 100;
                    }
                    else
                    {
                        cc.hsvImage[i, j].s = (byte)(tmpS);
                    }
                    //яркость
                    int tmpV = cc.hsvImage[i, j].v + trackBar3.Value;
                    if (tmpV < 0)
                    {
                        cc.hsvImage[i, j].v = 0;
                    }
                    else if (tmpS >= 100)
                    {
                        cc.hsvImage[i, j].v = 100;
                    }
                    else
                    {
                        cc.hsvImage[i, j].v = (byte)(tmpV);
                    }
                }
            }

            trackBar1.Value = 0;
            trackBar2.Value = 0;
            trackBar3.Value = 0;
            cc.ConvertHSVimagetoRGB();
            pictureBox1.Image = cc.rgbImage;
            //this.Cursor = Cursor.Default;
        }