What I am trying to do is make a routine that take a System.Drawing.Color and a System.Drawing.Bitmap in and returns a region excluding the passed in color. Sounds kinda easy. At least I thought so..... I have overflow in System.Drawing.dll......

Code:
public System.Drawing.Region ToRegion(System.Drawing.Color color, System.Drawing.Bitmap image)
{
	System.Drawing.Color c;
    	System.Drawing.Region r1 = null;
    	System.Drawing.Region r2 = null;

    	int[] colors = new int[] {System.Drawing.ColorTranslator.ToWin32(color),0}
    
	for(int x = 0; x < image.Width; x++)
    	{
        	for(int y = 0; y < image.Height; y++)
        	{
                	c = image.GetPixel(x, y);
                	colors[1] = System.Drawing.ColorTranslator.ToWin32(c);
                	if(color[0] != color[1])
                	{
                        	if(r1 == null)
                        	{
                                	r1 = new System.Drawing.Region(new System.Drawing.Rectangle(x, y, x + 1, y + 1));
                        	}
                        	else
                        	{
                               		r2 = new System.Drawing.Region(new System.Drawing.Rectangle(x, y, x + 1, y + 1));
                               		r1.Union(r2); //I'm not sure on this either
                        	}
                	}
        	}
    	}
    	return r1;
}
As far as I can tel that code should work and it returns with no errors, BUT when you go say
Code:
frm.Region = ToRegion(System.Drawing.Color.Black, imgIGotFromFile);
it runs, and runs, and runs, and System.OverFlowExeption in system.drawing.dll

I also tried GrapicsPath.AddRectangle and the contructing a Region from the path but same overflow error.

I don't want to use API if I can avoid it. Especially since it should work in the framework. I have vb6 code just like this using Region Api and SetWindowRgn that works......

Help!!!!