Negative image in c#

Call the following  function which takes one bitmap image and it returns one image.

 

        public Bitmap Generate_negative_image(Bitmap sourceimage)

        {                     

            Color c;

            for (int i = 0; i < sourceimage.Width; i++)

            {

                for (int j = 0; j < sourceimage.Height; j++)

                {

                    c = sourceimage.GetPixel(i,j);

                    c = Color.FromArgb(255 - c.R, 255 - c.G, 255 - c.B);

                    sourceimage.SetPixel(i, j, c);

                }

            }

 

                return sourceimage;

        }

 

How to call.:

        protected void button1_Click_1(object sender, EventArgs e)

        {

            pictureBox1.Image = Generate_negative_image((Bitmap)pictureBox1.Image);

           

        }

Here I am taking one image from picturebox , then it is type casted in bitmap and then passed to the function .

And it returned image is assigned to picturebox.

 

Ebook Download
View all
Learn
View all