First of all you dont need:
Color col = new Color();
because
GetPixel(x,y)
will return instance of Color class.
You can not use GetPixel() after you call LockBits() on same bitmap. That's why you get memory errors.
One solution is to use 'safe' code - do not call
LockBits()
and use
GetPixel()
to read from bitmap and
SetPixel()
to write to it. This can be slow on larger bitmaps, but you don't have to worry about bits per pixel (GDI does that).
Faster (unsafe) solution is to call
LockBits()
and then read pixel data through pointer:
seedR = p[x]
seedR = p[x+1]
seedR = p[x+2]
and write pixel data:
p[x]=p[x+1]=p[x+2]=0
Also your inner loop is not good, change it to something like:
for(int i=0; i<10; i++)
{
p[x]=p[x+1]=p[x+2]=0;
x++;
}
This will only work for 24bpp bitmaps. For any other you'll need more pointer arithmetic :)