1 Mayıs 2016 Pazar

Resmin içindeki ana renkleri bulan c# programı - C# Primary colour pixel calculator

Merhaba Arkadaşlar,

Bugün görüntü işlemede işinize yarayacağını düşündüğüm ufak bir araştırmamı sizinle paylaşmak istedim. Program C:\ dizininde bulunan bir görüntünün ana renklerini rakam olarak size geri döndürecek. İsterseniz tıklayıp upload görüntü ekleme özelliklerini kendiniz ekleyip geliştirebilirsiniz.(Ben üşendim itiraf ediyorum ne yazıkki.)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
          Bitmap myBitmap = new Bitmap(@"C:\6.png"); //Be careful about directory you may change. Görüntü dizinine dikkat
            int a = 0, b = 0, c = 0;
            for (int x = 0; x < myBitmap.Width; x++)
            {
                for (int y = 0; y < myBitmap.Height; y++)
                {

                    // Get the color of a pixel within myBitmap.
                    Color pixelColor = myBitmap.GetPixel(x, y);
                    string pixelColorStringValue =
                        pixelColor.R.ToString("D3") + //To get red pixels
                        pixelColor.G.ToString("D3") + //
To get Ged pixels                        
                        pixelColor.B.ToString("D3");   //To get Blue Pixels
                   
                        switch (pixelColorStringValue.ToString()) // Pixelimizi Süzgeçten geçiriyoruz // Let's filter pixel
                      {
                          case "255000000": // Kırmızı pikselin kodu
                              {
                                 
                                  a++;
                              } break;
                          case "000000225": // blue pixel code
                              {
                                 
                                  b++;
                              } break;
                          case "000225000": // green pixel code
                              {
                                  c++;
                              } break;       
                    }
                }
            }
            MessageBox.Show("bitti  " + a + " tane red pixel " + b + " tane blue pixel" + c + " tane green pixel");

            MessageBox.Show("It's done picture has " + a + " red pixel,   " + b + " blue pixel,  " + c + " green pixel"); 

        }
    }
}


Form design just has one button1 so I didn't attach. I will translate introducing part soon.
 

Hiç yorum yok:

Yorum Gönder

Yorum yaptığınız için teşekkür ederiz.