2012-12-06 3 views
0

이 방법으로 이미지를 전달하고 오른쪽 가장자리가 희미 해지고 있습니다. 갑자기 더 이상 작동하지 않습니다. 그것은 내가 전달하는 비트 맵을 반환하지만 수정 된 픽셀을 유지하지 않으면 원본으로 돌아옵니다. 내가 어디로 잘못 가고 있니?반환하는 비트 맵이 제대로 반환되지 않는 이유는 무엇입니까?

private Bitmap fadedEdge(Bitmap bmp) 
{ 
    //img.Save("i.bmp"); 
    //Bitmap bmp = (Bitmap)img; 
    int howfartofade = bmp.Width/4; 
    int i = 0; 
    if (howfartofade > 255) i = howfartofade/255; 
    else i = 255/howfartofade; 
    if (i == 0) i = 1; 
    int alp = 255; 
    int counter = 0; 
    for (int x = bmp.Width - howfartofade; x < bmp.Width; x++) 
    { 
     if (howfartofade > 255) 
     { 
      counter++; 
      if (counter == i + 1) 
      { 
       alp -= 1; 
       counter = 0; 
      } 
     } 
     else 
     { 
      alp -= i; 
     } 
     for (int y = 0; y < bmp.Height; y++) 
     { 
      if (alp >= 0) 
      { 
       Color clr = bmp.GetPixel(x, y); 
       clr = Color.FromArgb(alp, clr.R, clr.G, clr.B); 
       bmp.SetPixel(x, y, clr); 
      } 
      else 
      { 
       Color clr = bmp.GetPixel(x, y); 
       clr = Color.FromArgb(0, clr.R, clr.G, clr.B); 
       bmp.SetPixel(x, y, clr); 
      } 
     } 
    } 
    return bmp; 
} 
+1

왜 'bmp'를 반환합니까? 그것은 매개 변수로 전달되고'Bitmap'은 참조 유형 (클래스)입니다. – Dai

+2

Bitmap 개체에 알파 채널이 있습니까? bmp.PixelFormat을 확인하십시오. –

답변

0

알아 냈습니다. 바보 야. 이미지를 전달하고 이미지를 반환하도록 이미지를 변경하고 전달 된 이미지에서 새 비트 맵을 만들었습니다.

private Image fadedEdge(Image input) 
    { 
     //img.Save("i.bmp"); 
     //Bitmap bmp = (Bitmap)img; 
     Bitmap output = new Bitmap(input); 
     int howfartofade = input.Width/8; 
     int i = 0; 
     if (howfartofade > 255) i = howfartofade/255; 
     else i = (255/howfartofade) + 1; 
     if (i == 0) i = 1; 
     int alp = 255; 
     int counter = 0; 
     for (int x = input.Width - howfartofade; x < input.Width; x++) 
     { 
      if (howfartofade > 255) 
      { 
       counter++; 
       if (counter == i + 1) 
       { 
        alp -= 1; 
        counter = 0; 
       } 
      } 
      else 
      { 
       alp -= (i); 
      } 
      for (int y = 0; y < input.Height; y++) 
      { 
       if (alp >= 0) 
       { 
        Color clr = output.GetPixel(x, y); 
        clr = Color.FromArgb(alp, clr.R, clr.G, clr.B); 
        output.SetPixel(x, y, clr); 
       } 
       else 
       { 
        Color clr = output.GetPixel(x, y); 
        clr = Color.FromArgb(0, clr.R, clr.G, clr.B); 
        output.SetPixel(x, y, clr); 
       } 
      } 
     } 

     return output; 
    } 
관련 문제