Bitmap, Width, Height, GetPixel, SetPixel, ToByte


  private void button1_Click(object sender, System.EventArgs e)
  {
    Bitmap bitmap = new Bitmap("C:\\640480.bmp");
    int bwidth = bitmap.Width;
    int bheight = bitmap.Height;

    this.Width=bwidth;
    this.Height=bheight;

    int i, j;
    byte gray;
    for (i = 0; i<bwidth; i++)
    {
     for (j=0; j<bheight; j++)
     {
       Color pixelColor = bitmap.GetPixel(i, j);
       int r = pixelColor.R; // the Red component
       int g = pixelColor.G; // the Red component
       int b = pixelColor.B; // the Blue component
       gray=Convert.ToByte(r*0.3+g*0.6+b*0.1);
       Color newColor = Color.FromArgb(gray, gray, gray);
       bitmap.SetPixel(i, j, newColor);
      }
    }

    this.BackgroundImage = bitmap;
  }



댓글

댓글 쓰기

이 블로그의 인기 게시물

파이썬으로 Homomorphic Filtering 하기

파이썬으로 2D FFT/iFFT 하기: numpy 버전