1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class F_Main : Form
{
public F_Main()
{
InitializeComponent();
}
/// Acces à l'image de pictureBox1 (F_Main)
/// Pour passage vers F_NDG
public Image img_picturebox()
{
Image img;
img = pictureBox1.Image;
return img;
}
/// END
private void F_Main_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void pictureBox2_Click(object sender, EventArgs e)
{
}
private void fermerToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
void ouvrir_Click_1(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Image Files | *.png;*.jpg;*.bmp;*.jpeg;*.bmp";
DialogResult result = ofd.ShowDialog();
if (result == DialogResult.OK)
{
string picture_path = ofd.FileName;
Bitmap picture = (Bitmap)Bitmap.FromFile(picture_path);
this.pictureBox1.Image = picture;
byte[] pixel_map = this.GetPixelMap(picture);
this.pictureBox2.Image = this.CreateHistogram(pixel_map);
this.comboBox1.Enabled = true;
}
}
private byte[] GetPixelMap(Bitmap picture)
{
int size = picture.Width * picture.Height;
int channel_index = this.comboBox1.SelectedIndex;
int picture_width = picture.Width;
int picture_height = picture.Height;
byte[] pixels_map = new byte[size];
for (int i = 0; i < picture_height; i++)
{
for (int j = 0; j < picture_width; j++)
{
Color color = picture.GetPixel(j, i);
byte color_intensity = 0;
switch (channel_index)
{
case 0:
color_intensity = color.R;
break;
case 1:
color_intensity = color.G;
break;
case 2:
color_intensity = color.B;
break;
}
pixels_map[j + picture_width * i] = color_intensity;
}
}
return pixels_map;
}
private Bitmap CreateHistogram(byte[] pixel_map)
{
int size = pixel_map.Length;
int index = this.comboBox1.SelectedIndex;
int[] histogram = new int[256];
int max = 0;
for (int i = 0; i < size; i++)
{
int pixel_value = pixel_map[i];
histogram[pixel_value]++;
if (histogram[pixel_value] > max)
{
max = histogram[pixel_value];
}
}
Point[] points = new Point[Byte.MaxValue + 3];
points[0].X = 0;
points[0].Y = 190;
for (int i = 0; i < Byte.MaxValue + 1; i++)
{
points[i + 1].X = i;
points[i + 1].Y = Convert.ToInt32(190 - Convert.ToDouble(histogram[i]) / max * 180);
}
points[Byte.MaxValue + 2].X = Byte.MaxValue;
points[Byte.MaxValue + 2].Y = 190;
Bitmap picture_histogram = new Bitmap(300, 300);
Graphics graphic_histogram = Graphics.FromImage(picture_histogram);
Pen pen = new Pen(Color.Black);
pen.Brush = new SolidBrush(Color.Black);
graphic_histogram.FillPolygon(pen.Brush, points);
graphic_histogram.DrawLine(pen, new Point(0, 195), new Point(260, 195));
graphic_histogram.DrawLine(pen, new Point(255, 197), new Point(260, 195));
graphic_histogram.DrawLine(pen, new Point(255, 193), new Point(260, 195));
return picture_histogram;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Bitmap picture = (Bitmap)this.pictureBox1.Image;
if (picture != null)
{
byte[] pixel_map = this.GetPixelMap(picture);
this.pictureBox2.Image = this.CreateHistogram(pixel_map);
}
}
private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{
}
private void Btn_Taille_Click(object sender, EventArgs e)
{
if (pictureBox1.Image != null)
{
B_Affi_Taille1.Text = (pictureBox1.Image.Width.ToString());
B_Affi_Taille2.Text = (pictureBox1.Image.Height.ToString());
Total.Text = (pictureBox1.Image.PixelFormat.ToString());
}
else
{
MessageBox.Show("Erreur de chargement");
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Image Files | *.png;*.jpg;*.bmp;*.jpeg;*.bmp";
DialogResult result = ofd.ShowDialog();
}
}
private void sauverImageToolStripMenuItem_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height);
Graphics g = Graphics.FromImage(bmp);
bmp.Save(@"c:/picturebox.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
MessageBox.Show("Image Enregistrée");
}
private void niveauDeGrisToolStripMenuItem_Click_1(object sender, EventArgs e)
{
Bitmap _img = new Bitmap(pictureBox1.Width,pictureBox1.Height);
F_NDG Fndg = new F_NDG(_img);
Fndg.Show();
}
private void egalisationToolStripMenuItem_Click(object sender, EventArgs e)
{
Bitmap _img2 = new Bitmap(pictureBox1.Width, pictureBox1.Height);
F_Egal F2 = new F_Egal(_img2);
F2.Show();
}
private void planCouleurToolStripMenuItem_Click(object sender, EventArgs e)
{
Bitmap _img3 = new Bitmap(pictureBox1.Width, pictureBox1.Height);
F_Plan F3 = new F_Plan(_img3);
F3.Show();
}
private void Btn_Traiter_Click(object sender, EventArgs e)
{
Bitmap picture = (Bitmap)this.pictureBox1.Image;
if (picture != null)
{
// this.pictureBox4.Image = MakeGrayscale(picture);
}
}
}
} |
Partager