悬赏园豆:20
[已关闭问题]
<pre>代码如下:主要想把bmp中指定的和某种颜色相似的颜色替换为透明色(或者其他颜色)<br /> public Bitmap MyGamma(Bitmap bmp)<br /> {<br /> ImageAttributes imageAttr = new ImageAttributes();<br /><br /> //Color ChangeOld = Color.FromArgb(255, 255, 255);//要替换的颜色<br /><br /> Color ChangeNew = Color.FromArgb(0, 0, 0, 0);//替换后的颜色<br /><br /><br /> ColorMap[] map = new ColorMap[255];//定义一个容差<br /> for (int i = 0; i < map.Length; i++)<br /> {<br /> map[i].OldColor = Color.FromArgb(i,255, 255, 255);<br /> map[i].NewColor = ChangeNew;<br /> }<br /><br /><br /> imageAttr.SetRemapTable(map, ColorAdjustType.Bitmap);<br /><br /> Graphics GDI = Graphics.FromImage(bmp);<br /> int w = bmp.Width;<br /> int h = bmp.Height;<br /><br /> Rectangle rect = new Rectangle(0, 0, w, h);<br /> GDI.DrawImage(bmp, rect, 0, 0, w, h, GraphicsUnit.Pixel, imageAttr);<br /><br /> return bmp;<br /> }<br /><br />问题出在map[i].OldColor = Color.FromArgb(i,255, 255, 255);<br /><br />一般情况下,使用如下语句正常<br />ColorMap colorMap = new ColorMap();<br /><br />colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);<br />colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);<br />ColorMap[] remapTable = { colorMap };<br /><br />我想,既然ColorMap[]是数组,所以就.....没想到出错了,按道理不应该啊......<br />问问各位大虾怎么解决<br /><br />总之实现 想把bmp中指定的和某种颜色相似的颜色(指定一个颜色容差)替换为透明色或者指定颜色就好...先谢了!!<br /><br />问题补充:<br /><br />不要使用GetPixel,我通过这种方法做了,效率低!!! </pre>