2013-11-01 5 views
0

이미지의 픽셀을 일부 스캔하기 위해 C# 프로그램을 작성했습니다. 이것은 아마 5 번만 실행하려고하는 프로그램을위한 것이므로 효율적 일 필요는 없습니다.이미지를 조작 할 때 표시

각 픽셀을 읽은 후 색상을 변경하고 이미지 디스플레이를 업데이트하여 스캔 진행 상황과 발견되는 부분을 볼 수 있지만 표시 할 내용을 얻을 수는 없습니다. 좋은 예를 알기 전에 누군가 이렇게 했습니까?

편집 : 현재 사용하려는 코드는 다음과 같습니다.

void Main() 
{ 
    Bitmap b = new Bitmap(@"C:\test\RKB2.bmp"); 
    Form f1 = new Form(); 
    f1.Height = (b.Height /10); 
    f1.Width = (b.Width/10); 
    PictureBox PB = new PictureBox(); 
    PB.Image = (Image)(new Bitmap(b, new Size(b.Width, b.Height))); 
    PB.Size = new Size(b.Width /10, b.Height /10); 
    PB.SizeMode = PictureBoxSizeMode.StretchImage; 
    f1.Controls.Add(PB); 
    f1.Show(); 
    for(int y = 0; y < b.Height; y++) 
    { 
     for(int x = 0; x < b.Width; x++) 
     { 
      if(b.GetPixel(x,y).R == 0 && b.GetPixel(x,y).G == 0 && b.GetPixel(x,y).B == 0) 
      { 
       //color is black 
      } 
      if(b.GetPixel(x,y).R == 255 && b.GetPixel(x,y).G == 255 && b.GetPixel(x,y).B == 255) 
      { 
       //color is white 
       Bitmap tes = (Bitmap)PB.Image; 
       tes.SetPixel(x, y, Color.Yellow); 
       PB.Image = tes; 
      } 
     } 

    } 
} 
+1

당신은 몇 가지를 추가 할 수 지금까지 무엇을하고 있는지 보여주는 코드? – littleimp

+2

이것은 WPF 앱입니까? 아니면 다른 것입니까? –

+0

WinForms? 'PictureBox' 사용하기? –

답변

0

이미지 처리 작업과 업데이트 작업을 분리해야합니다. 좋은 시작은 Windows Forms 프로젝트를 만들고 폼과 단추에 PictureBox 컨트롤을 추가하는 것입니다. 단추를 조치에 바인드하고 조치에서 처리를 시작하십시오. 그러면 업데이트 프로세스가 표시됩니다. 코드이 변경되는 경우, 다음 최종 변환이 볼 수 있어야합니다 : (내 테스트 이미지) 변경 결과 후

void Main() 
{ 
    Bitmap b = new Bitmap(@"C:\test\RKB2.bmp"); 
    Form f1 = new Form(); 
    f1.Height = (b.Height /10); 
    f1.Width = (b.Width/10); 
    // size the form 
    f1.Size = new Size(250, 250); 
    PictureBox PB = new PictureBox(); 
    PB.Image = (Image)(new Bitmap(b, new Size(b.Width, b.Height))); 
    PB.Size = new Size(b.Width /10, b.Height /10); 
    PB.SizeMode = PictureBoxSizeMode.StretchImage; 
    PB.SetBounds(0, 0, 100, 100); 
    Button start = new Button(); 
    start.Text = "Start processing"; 
    start.SetBounds(100, 100, 100, 35); 
    // bind the button Click event 
    // The code could be also extracted to a method: 
    // private void startButtonClick(object sender, EventArgs e) 
    // and binded like this: start.Click += startButtonClick; 
    start.Click += (s, e) => 
    { 
     for(int y = 0; y < b.Height; y++) 
     { 
      for(int x = 0; x < b.Width; x++) 
      { 
       if(b.GetPixel(x,y).R == 0 && b.GetPixel(x,y).G == 0 && b.GetPixel(x,y).B == 0) 
       { 
        //color is black 
       } 
       if(b.GetPixel(x,y).R == 255 && b.GetPixel(x,y).G == 255 && b.GetPixel(x,y).B == 255) 
       { 
        //color is white 
        Bitmap tes = (Bitmap)PB.Image; 
        tes.SetPixel(x, y, Color.Yellow); 
        PB.Image = tes; 
       } 
      } 
     } 
    }; 
    f1.Controls.Add(PB); 
    f1.Controls.Add(start); 
    f1.Show(); 
} 

은 다음과 같습니다

test form

+0

그는 이것이 WinForms, WebForms, Console 또는 다른 것인지 언급하지 않았습니다. –

관련 문제