1.先把图像转成数组(二进制流),遍历,判断哪些连续的颜色相同的像素是背景,把人物部分"抠"出来
2.将另一个背景图片作为底图,同样转数组,将人物部分循环赋值进去
3.将新数组重新转回图像显示

解决方案 »

  1.   

        Bitmap _tmpB = null;
                    if (_tmpB != null)
                        _tmpB.Dispose();
                    //释放旧临时图内存
                    Color SourceColor = SourceBitmap.GetPixel(1, 1);
                    _tmpB = new Bitmap(SourceBitmap);
                    System.Drawing.Imaging.BitmapData bmpDATA = new System.Drawing.Imaging.BitmapData();
                    bmpDATA = _tmpB.LockBits(new Rectangle(0, 0, _tmpB.Width, _tmpB.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    byte[] BTS = new byte[bmpDATA.Stride * bmpDATA.Height + 1];
                    System.Runtime.InteropServices.Marshal.Copy(bmpDATA.Scan0, BTS, 0, BTS.Length - 1);
                    for (int I = 0; I <= BTS.Length - 4; I += 4)
                    {
                        if (IsNearValue(BTS[I], BTS[I + 1], BTS[I + 2], SourceColor, Tolerance) == true)
                        {
                            BTS[I + 3] = 0;
                        }
                    }
                    System.Runtime.InteropServices.Marshal.Copy(BTS, 0, bmpDATA.Scan0, BTS.Length - 1);
                    _tmpB.UnlockBits(bmpDATA);
                    return _tmpB;
      

  2.   

    把纯色背景替换为透明,然后画到其它背景图上。
      

  3.   

    抠图有没有更好的办法 这样抠图效果还是不太好 容差如何自动计算
      

  4.   

    想要容差,那么你需要给出阀值,然后判断差在某个范围内,都当背景处理
    不过这需要你自己进行测试,没有标准
    跟你给出的目标图片的背景色差,前景色差,都有关系
    如果阀值设置的过小,那么背景可能不完整(把部分背景当人物了)
    如果阀值设置的过大,而前景色差比较小,那么可能把人物一部分当做背景了