Пример #1
0
 /// <summary>
 /// Convert this color to an hex string with format #AARRGGBB
 /// </summary>
 /// <returns>Hex string.</returns>
 public string ColorToHex()
 {
     return(String.Format("#{0}{1}{2}{3}"
                          , Ab.ToString("X").Length == 1 ? String.Format("0{0}", Ab.ToString("X")) : Ab.ToString("X")
                          , Rb.ToString("X").Length == 1 ? String.Format("0{0}", Rb.ToString("X")) : Rb.ToString("X")
                          , Gb.ToString("X").Length == 1 ? String.Format("0{0}", Gb.ToString("X")) : Gb.ToString("X")
                          , Bb.ToString("X").Length == 1 ? String.Format("0{0}", Bb.ToString("X")) : Bb.ToString("X")));
 }
        //平均梯度
        private void button1_Click(object sender, EventArgs e)
        {
            double Gr, Gg, Gb;
            int    delt_xr, delt_yr, delt_xg, delt_yg, delt_xb, delt_yb;

            double map_r, map_g, map_b;

            map_r = map_g = map_b = 0;

            for (int i = 0; i < newBitmap.Width - 1; i++)
            {
                for (int j = 0; j < newBitmap.Height - 1; j++)
                {
                    Color pixel   = newBitmap.GetPixel(i, j);
                    Color pixel_x = newBitmap.GetPixel(i + 1, j);
                    Color pixel_y = newBitmap.GetPixel(i, j + 1);

                    delt_xr = (pixel_x.R - pixel.R) * (pixel_x.R - pixel.R);
                    delt_yr = (pixel_y.R - pixel.R) * (pixel_y.R - pixel.R);

                    delt_xg = (pixel_x.G - pixel.G) * (pixel_x.G - pixel.G);
                    delt_yg = (pixel_y.G - pixel.G) * (pixel_y.G - pixel.G);

                    delt_xb = (pixel_x.B - pixel.B) * (pixel_x.B - pixel.B);
                    delt_yb = (pixel_y.B - pixel.B) * (pixel_y.B - pixel.B);

                    map_r += Math.Sqrt(delt_xr + delt_yr);
                    map_g += Math.Sqrt(delt_xg + delt_yg);
                    map_b += Math.Sqrt(delt_xb + delt_yb);
                }
            }

            Gr = map_r / ((newBitmap.Width - 1) * (newBitmap.Height - 1));
            Gg = map_g / ((newBitmap.Width - 1) * (newBitmap.Height - 1));
            Gb = map_b / ((newBitmap.Width - 1) * (newBitmap.Height - 1));

            MessageBox.Show("融合图三通道平均梯度" + "\r\n" + "Gr:" + Gr.ToString() + "   " + "Gg:" + Gg.ToString() + "   " + "Gb:" + Gb.ToString());
        }