我正在将图像传递给这个方法并淡化它的右边缘,它正在工作,但突然不再起作用了。它正在返回我传递给它的位图,但不保留修改后的像素,它们会恢复原状。我哪里错了?
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;
}