现在我有一张人物照片,背景是纯色的(注:这里的纯色是指单一颜色,因为通过相机拍照后,颜色RGB值变化很大,比如看起来是红色,GB的值就有很大的不同)。
我现在需要把照片里面的人物扣出来,然后替换背景。
大家有么好的思路。
我现在需要把照片里面的人物扣出来,然后替换背景。
大家有么好的思路。
解决方案 »
- Webservice能通过配置文件引用吗??
- 未处System.StackOverflowException 确保程序没有无限循环或无线递归
- 还是谈谈堆和栈:为什么这段程序会死机
- Tao framework下怎么用OpenGL扩展函数?!
- 使用api getwindowtext 取gb18030字符
- C++代码转成C#的问题
- updater Application block v2.0使用问题?
- 两个GridView嵌套着RadioButton,如何取RadioButton的值
- winform 无边框窗体内toppanel midpanel bottompanel 填充,怎么拖动改变窗体大小
- 单击编辑图标,获取该行的标题名字,怎么实现?
- 类前面 类似 [Serializable] 称作什么?
- 想用c#做个音乐播放器
{
Color pixelColor = bmp.GetPixel(1, 1);
//像素点颜色的 Alpha 值
byte alpha = pixelColor.A;
//颜色的 RED 分量值
byte red = pixelColor.R;
//颜色的 GREEN 分量值
byte green = pixelColor.G;
//颜色的 BLUE 分量值
byte blue = pixelColor.B;
}
分析图片的ARGB试试
/// <summary>
/// 获取经容差计算后的最终图,参考色彩点为源图坐标(1,1)
/// </summary>
/// <param name="SourceBitmap">源图</param>
/// <param name="Tolerance">容差</param>
/// <returns></returns>
/// <res></res>
private Bitmap GetFinalBitmap_Forli_007(Bitmap SourceBitmap, int Tolerance)
{
try {
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), Imaging.ImageLockMode.ReadWrite, 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;
} catch {
return null;
}
}
private bool IsNearValue(int B, int G, int R, Color Cr, int Tol)
{
try {
if (Math.Max(Cr.B, B) - Math.Min(Cr.B, B) <= Tol && Math.Max(Cr.G, G) - Math.Min(Cr.G, G) <= Tol && Math.Max(Cr.R, R) - Math.Min(Cr.R, R) <= Tol) {
return true;
} else {
return false;
}
} catch {
return false;
}
}
楼主的头像是很好的例子,牙齿与耳朵很难处理的。