Görüntü İşleme-1 C# İstediğimiz Pikselin RGB' Değerlerine Ulaşma-image processing
Merhaba arkadaşlar bugün bir fotoğraftaki rgblere(Red,Green,Blue) yani renk kodlarına nasıl ulaşacağımızı anlatacağım.
1-)Öncelikle yeni bir proje oluşturuyoruz.
2-)Daha sonra projemize şekildeki öğeleri ekliyoruz.
3-) Şimdi kod yazmaya geldi sıra butona çift tıklayarak kod kısmına geçiyoruz ve kodumuzu yazmaya başlıyoruz.
4-)Şimdi biz x ve y textboxlarına birer sayı gireceğiz yani resimdeki istediğimiz pikselin weight ve hight değerlerini sonra rgb göster butonuna bastığımızda aşağıdaki txt boxlara yazdığımız pikselin rgb değerleri yazdırılacak.
5-)Önceki yazımızda resim seçme işlemini yaptığımız için burada tekrardan anlatmiyacağım.
private void button1_Click(object sender, EventArgs e)
{
String text_x = textBox1.Text;
String text_y = textBox2.Text;
int x = 0;
int y = 0;
try
{
x = Int32.Parse(text_x);
y = Int32.Parse(text_y);
}
catch (FormatException err)
{
MessageBox.Show(this, err.Message);
}
Bitmap image = (Bitmap)pictureBox1.Image;
Color renk = image.GetPixel(x, y);
string sayi = Convert.ToString(renk.G);
textBox3.Text = sayi;
string sayi1 = Convert.ToString(renk.R);
textBox4.Text = sayi1;
string sayi2 = Convert.ToString(renk.B);
textBox5.Text = sayi2;
}
private void button2_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "RESİM SEÇ";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(openFileDialog1.OpenFile());
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
6-) Şimdide programımızı derleyip çalıştırıyoruz.
Bir sonraki yazımızda görüşmek dileğiyle :)
Yorumlar
Yorum Gönder