图片替换颜色问题?
图片替换颜色保存图片之后发现替换的颜色仍有存在?只替换了部分
原来没有"#010101"颜色的地方也会出现部份这种颜色,
寻求解决办法!
代码
public const string fileName = @"E:\ld.jpg";
public const string gName = @"e:\test1.jpg";
public string j01 = "#010101";
public string j00 = "#000000";
protected void Page_Load(object sender, EventArgs e)
{
Bitmap btm = new Bitmap(fileName);
int w = btm.Width;
int h = btm.Height;
Bitmap btm2 = new Bitmap(w, h);
int k = 0;
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
Color cTmp = btm.GetPixel(x, y);
Color c = ColorTranslator.FromHtml(j01);
if (cTmp.ToArgb()==c.ToArgb() )
{
btm.SetPixel(x, y, ColorTranslator.FromHtml(j00));
k = k + 1;
}
}
}
Response.Write(k);
btm.Save(gName);
Response.Write("ok!");
}