using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Ex13_07
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
//
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = " (JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png| JPeg (*.jpg;*.jpeg)|*.jpg;*.jpeg |GIF (*.gif)|*.gif |BMP (*.bmp)|*.bmp|Tiff (*.tif;*.tiff)|*.tif;*.tiff|Png (*.png)| *.png | (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
Bitmap MyBitmap = new Bitmap(openFileDialog.FileName);
this.pictureBox1.Image = MyBitmap;
}
}
private void button1_Click(object sender, EventArgs e)
{
//
try
{
int Height = this.pictureBox1.Image.Height;
int Width = this.pictureBox1.Image.Width;
Bitmap newbitmap = new Bitmap(Width, Height);
Bitmap oldbitmap = (Bitmap)this.pictureBox1.Image;
Color pixel;
for (int x = 1; x < Width; x++)
{
for (int y = 1; y < Height; y++)
{
int r, g, b;
pixel = oldbitmap.GetPixel(x, y);
r = 255 - pixel.R;
g = 255 - pixel.G;
b = 255 - pixel.B;
newbitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
}
}
this.pictureBox1.Image = newbitmap;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}