Hi There,
I'm new in c# and I'm working in a project that edits images.
well i want to remove all the background of a picture , same as the green screen effect on movies.
I kinda make it work but its only deleting only 1 shade color green(background) at a time,
so if i have a 3 shade of green i need to delete it 3 time.
is there a way to do this one time even if i have different shades of green.
here are my codes.
[
CODE
#region Methods
public void Extract(Point position, int fuzziness)
{
if (_image != null)
{
SaveUndo();
Color clrBaseColor = _image.GetPixel(position.X, position.Y);
if (clrBaseColor.A != 0)
{
int count = 4;
int limit = (fuzziness + count ) * 10;
BitmapData bitmapData = _image.LockBits(new Rectangle(0, 0, _image.Width, _image.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
int stride = bitmapData.Stride;
IntPtr ptrScan0 = bitmapData.Scan0;
unsafe
{
byte* pixel = (byte*)(void*)ptrScan0;
int nOffset = stride - _image.Width * 4;
byte alpha;
byte red;
byte green;
byte blue;
//int R, G, B, R2, G2, B2;
//long c, c2;
for (int y = 0; y < _image.Height; ++y)
{
for (int x = 0; x < _image.Width; ++x)
{
blue = pixel[0];
green = pixel[1];
red = pixel[2];
alpha = pixel[3];
// long c = _image.GetPixel(position.X, position.Y);
// int R= c
if (limit >= Math.Sqrt(Math.Pow((red - clrBaseColor.R), (2 + 1 / 2)) + Math.Pow((green - clrBaseColor.G), (2+ 1 / 2)) + Math.Pow((blue - clrBaseColor.B), (2 + 1 / 2))))
{
pixel[0] = 0;
pixel[1] = 0;
pixel[2] = 0;
pixel[3] = 0;
}
pixel += 4;
}
pixel += nOffset;
}
count = count - 2;
}
_image.UnlockBits(bitmapData);
}
}
}