对图像的浮雕处理。。

来源:互联网 发布:淘宝怎么可以买到rush 编辑:程序博客网 时间:2024/04/27 16:12

对图像的浮雕处理。。

2011278:51:39

 

     /// <summary>

         /// 应用程序的主入口点。

         /// </summary>

         [STAThread]

         static void Main()

         {

              Application.Run(new Form1());

         }

        

         Bitmap bmp;

         private void button1_Click(object sender, System.EventArgs e)

         {

              if(this.openFileDialog1.ShowDialog()==DialogResult.OK)

              {

                bmp = new Bitmap(this.openFileDialog1.FileName);

 

 

                ///---  这里是渲染浮雕的过程

                for (int i = 0; i < bmp.Width - 1; i++)

                {

                    for (int j = 0; j < bmp.Height - 1; j++)

                    {

                        Color Color1 = bmp.GetPixel(i, j);

                        Color Color2 = bmp.GetPixel(i + 1, j + 1);

                        int red = Math.Abs(Color1.R - Color2.R + 128);

                        int green = Math.Abs(Color1.G - Color2.G + 128);

                        int blue = Math.Abs(Color1.B - Color2.B + 128);

                        //颜色处理

                        if (red > 255) red = 255;

                        if (red < 0) red = 0;

 

                        if (green > 255) green = 255;

                        if (green < 0) green = 0;

 

                        if (blue > 255) blue = 255;

                        if (blue < 0) blue = 0;

                        bmp.SetPixel(i, j, Color.FromArgb(red, green, blue));

                        // 表示在指定的委托进行相应色的改变

                    }

                }

                   this.pictureBox1.Image=bmp;

              }

            this.pictureBox1.Image.Save("D://bmp2.bmp");

         }

 

         private void Form1_Load(object sender, System.EventArgs e)

         {

              this.pictureBox1.SizeMode=PictureBoxSizeMode.StretchImage;

         }

        /// <summary>

        ///  move的时候了获取的是鼠标移动到某个点的原色信息

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)

        {

         

 

 

            if (this.pictureBox1.Image != null)

            {

                Bitmap bmp = (Bitmap)this.pictureBox1.Image;

 

                 /// 这里获取的是我们的委托对象中的某个颜色的值的信息

                try

                {

                    Color pixelColor = bmp.GetPixel(e.X, e.Y);

                    this.Text = "(" + pixelColor.R.ToString() + "," +

                                pixelColor.G.ToString() + "," + pixelColor.B.ToString() + ")";

                }

                catch {}

            }         

        }

 

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)

        {

           

           

        }

    }

}

原创粉丝点击