代码如下,我在黑白化的时候出错,说带有索引像素的图片 不能SetPixel,那怎么办?怎么解决这个问题
void whiteblack(Bitmap bmp)
{
for(int a=0;a<bmp.Width;a++)
{
for(int b=0;b<bmp.Height;b++)
{
int r=bmp.GetPixel(a,b).R;
int g=bmp.GetPixel(a,b).G;
int bb=bmp.GetPixel(a,b).B;
Color c;
int v=(r+g+bb)/3;
if(v>255/2)c=Color.FromArgb(255,255,255);
else
c=Color.FromArgb(0,0,0);
bmp.SetPixel(a,b,c);
}
}
}
void whiteblack(Bitmap bmp)
{
for(int a=0;a<bmp.Width;a++)
{
for(int b=0;b<bmp.Height;b++)
{
int r=bmp.GetPixel(a,b).R;
int g=bmp.GetPixel(a,b).G;
int bb=bmp.GetPixel(a,b).B;
Color c;
int v=(r+g+bb)/3;
if(v>255/2)c=Color.FromArgb(255,255,255);
else
c=Color.FromArgb(0,0,0);
bmp.SetPixel(a,b,c);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货