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;
}
你爲什麼要返回'bmp'?它作爲參數傳入,'Bitmap'是一個引用類型(一個類)。 – Dai
您的位圖對象是否有Alpha通道?檢查bmp.PixelFormat。 –