Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Drawing.Imaging;
- using System.IO;
- namespace PhotoEditor
- {
- public partial class Form1 : Form
- {
- Bitmap bmp = null;
- public Form1()
- {
- InitializeComponent();
- }
- System.Drawing.Image file;
- Boolean opened = false;
- private void button1_Click(object sender, EventArgs e)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- if (ofd.ShowDialog().Equals(DialogResult.OK))
- {
- string fname = ofd.FileName;
- bmp = (Bitmap)Bitmap.FromFile(fname);
- Bitmap b2 = new Bitmap(bmp, pictureBox1.Size);
- pictureBox1.Image = b2;
- }
- }
- private void trackBar1_Scroll(object sender, EventArgs e)
- {
- float changeb = trackBar1.Value * 0.1f;
- trackBar1.Text = changeb.ToString();
- System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
- Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
- and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
- ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
- ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
- {
- new float[]{1, 0, 0, 0, 0},
- new float[]{0, 1, 0, 0, 0},
- new float[]{0, 0, 1, 0, 0},
- new float[]{0, 0, 0, 1, 0},
- new float[]{0+changeb, 0+changeb, 0+changeb, 0, 1}
- });
- ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
- Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
- Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
- g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
- /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
- location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
- format of graphics unit,provide the image attributes */
- g.Dispose(); //Releases all resources used by this Graphics.
- pictureBox1.Image = bmpInverted;
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
- Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
- and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
- ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
- ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
- {
- new float[]{0.393f, 0.349f, 0.272f, 0, 0},
- new float[]{0.769f, 0.686f, 0.534f, 0, 0},
- new float[]{.189f, .168f, .131f, 0, 0},
- new float[]{0, 0, 0, 1, 0},
- new float[]{0, 0, 0, 0, 1}
- });
- ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
- Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
- Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
- g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
- /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
- location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
- format of graphics unit,provide the image attributes */
- g.Dispose(); //Releases all resources used by this Graphics.
- pictureBox1.Image = bmpInverted;
- }
- private void button3_Click(object sender, EventArgs e)
- {
- System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
- Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
- and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
- ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
- ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
- {
- new float[]{1.5f, 1.5f, 1.5f, 0, 0},
- new float[]{1.5f, 1.5f, 1.5f, 0, 0},
- new float[]{1.5f, 1.5f, 1.5f, 0, 0},
- new float[]{0, 0, 0, 1, 0},
- new float[]{-1, -1, -1, 0, 1}
- });
- ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
- Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
- Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
- g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
- /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
- location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
- format of graphics unit,provide the image attributes */
- g.Dispose(); //Releases all resources used by this Graphics.
- pictureBox1.Image = bmpInverted;
- }
- private void trackBar2_Scroll(object sender, EventArgs e)
- {
- float changec = trackBar2.Value * 0.1f;
- float t = 0;
- trackBar2.Text = changec.ToString();
- System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
- Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
- and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
- ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
- ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
- {
- new float[]{1+changec, 0, 0, 0, 0},
- new float[]{0, 1+changec, 0, 0, 0},
- new float[]{0, 0, 1+changec, 0, 0},
- new float[]{0, 0, 0, 1, 0},
- new float[]{t, t, t, 0, 1}
- });
- if (changec == 0)
- t = (1f - changec) / 2f;
- ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
- Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
- Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
- g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
- /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
- location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
- format of graphics unit,provide the image attributes */
- g.Dispose(); //Releases all resources used by this Graphics.
- pictureBox1.Image = bmpInverted;
- }
- private void button4_Click(object sender, EventArgs e)
- {
- }
- private void button5_Click(object sender, EventArgs e)
- {
- System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
- Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
- and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
- ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
- ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
- {
- new float[]{-1, 0, 0, 0, 1.00f},
- new float[]{0, -1, 0, 0, 1.00f},
- new float[]{0, 0, -1, 0, 1.00f},
- new float[]{0, 0, 0, 1, 0},
- new float[]{1, 1, 1, 0, 1}
- });
- ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
- Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
- Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
- g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
- /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
- location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
- format of graphics unit,provide the image attributes */
- g.Dispose(); //Releases all resources used by this Graphics.
- pictureBox1.Image = bmpInverted;
- }
- private void button6_Click(object sender, EventArgs e)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Images|*.png;*.bmp;*.jpg";
- ImageFormat format = ImageFormat.Png;
- if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- string ext = Path.GetExtension(sfd.FileName);
- switch (ext)
- {
- case ".jpg":
- format = ImageFormat.Jpeg;
- break;
- case ".bmp":
- format = ImageFormat.Bmp;
- break;
- }
- pictureBox1.Image.Save(sfd.FileName, format);
- }
- }
- private void button7_Click(object sender, EventArgs e)
- {
- System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
- Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
- and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
- ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
- ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
- {
- new float[]{1.438f, -0.062f, -0.062f, 0, 0},
- new float[]{-0.122f, 1.378f, -0.122f, 0, 0},
- new float[]{-0.016f, -0.016f, 1.483f, 0, 0},
- new float[]{0, 0, 0, 1, 0},
- new float[]{-0.03f, 0.05f, -0.02f, 0, 1}
- });
- ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
- Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
- Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
- g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
- /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
- location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
- format of graphics unit,provide the image attributes */
- g.Dispose(); //Releases all resources used by this Graphics.
- pictureBox1.Image = bmpInverted;
- }
- private void button8_Click(object sender, EventArgs e)
- {
- System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
- Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
- and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
- ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
- ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
- {
- new float[]{1, 4, 7, 4, 1},
- new float[]{4, 16, 26, 16, 4},
- new float[]{7, 26, 41, 26, 7},
- new float[]{4, 26, 16, 26, 4},
- new float[]{1, 4, 7, 4, 1}
- });
- ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
- Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
- Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
- g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
- /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
- location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
- format of graphics unit,provide the image attributes */
- g.Dispose(); //Releases all resources used by this Graphics.
- pictureBox1.Image = bmpInverted;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement