using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication54
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Bitmap image1;
Bitmap image2;
private void Button1_Click(System.Object sender, System.EventArgs e)
{
try
{
// Retrieve the image.
image1 = new Bitmap(pictureBox1.Image);
int x, y;
// Loop through the images pixels to reset color.
for (x = 0; x < image1.Width; x++)
{
for (y = 0; y < image1.Height; y++)
{
Color pixelColor = image1.GetPixel(x, y);
Color newColor = Color.FromArgb(100, pixelColor.R, pixelColor.G, pixelColor.B);
image1.SetPixel(x, y, newColor);
}
}
// Set the PictureBox to display the image.
pictureBox1.Image = image1;
// Display the pixel format in Label1.
label1.Text = "Pixel format: " + image1.PixelFormat.ToString();
}
catch (ArgumentException)
{
MessageBox.Show("There was an error." +
"Check the path to the image file.");
}
}
private void Button5_Click(System.Object sender, System.EventArgs e)
{
image2.Save(@"c:\1.jpg");
try
{
if (image1 != null)
{
image1.Save("c:\\myBitmap.bmp");
button2.Text = "Saved file.";
label1.Text += "Saved file.";
}
}
catch (Exception)
{
MessageBox.Show("There was a problem saving the file." +
"Check the file permissions.");
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
image2 = new Bitmap(pictureBox1.Image, pictureBox1.Image.Width , pictureBox1.Image.Height );
int x, y;
// Loop through the images pixels to reset color.
for (x = 0; x < image2.Width; x++)
{
for (y = 0; y < image2.Height ; y++)
{
Color pixelColor = image2.GetPixel(x, y);
Color newColor = Color.FromArgb(255, pixelColor.R, pixelColor.G, pixelColor.B);
image2.SetPixel(x, y, newColor);
}
}
// Set the PictureBox to display the image.
pictureBox1.Image = image2;
// Display the pixel format in Label1.
label1.Text = "Pixel format: " + image2.PixelFormat.ToString();
}
catch (ArgumentException)
{
MessageBox.Show("There was an error." +
"Check the path to the image file.");
}
}
}
}