Hi all,

I am trying to draw a custom hatch pattern on some rectangles. I have a 16 color bitmap that contains my desired hatch pattern, drawn in Black and White (White is the background, Black is the actual Hatch pattern), and loaded as an embedded resource. I want to be able to change the colors when I use the bitmap for a TextureBrush to something other than Black and White.

So, when I create the TextureBrush, I load in the bitmap, then change the first and last colors in the bitmap's palette to, let' say, Red and Yellow. I do this thusly:

Code:
public static Image LoadHatchPattern()
{
// Load the desired 16 color bitmap ("Hatch1.bmp") from the project's embedded resources (in the 'Textures' folder)

   Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("Designer.Textures.Hatch1.bmp");
 
// Create a bitmap from the stream, then change the first and last color (Black & White) to Yellow & Red.

   Bitmap b = new Bitmap(s);
   ColorPalette p = b.Palette;
 
   p.Entries[0] = Color.Red;
   p.Entries[15] = Color.Yellow;
 
   b.Palette = p;
 
   //b.MakeTransparent(Color.White);
   return b;
}

Here's the problem. If I use the returned Image object to create a TextureBrush, and then use that brush in a call to FillRectangle, the hatch color is still Black and White, not Red and Yellow like I want it to be!

Here's how I am doing it:

Code:
public override void Draw(Graphics g)
{
   Image image = Support.LoadHatchPattern();
 
// Test draw the converted bitmap as a bitmap.  This works (draws in Yellow & Red)!

   g.DrawImage(Support.LoadHatchPattern(1), SX-10, SY-10);
 
// Draw a filled rectangle using the SAME BITMAP for the brush.  This doesn't work (fills in Black & White)!

   TextureBrush b = new TextureBrush(Support.LoadHatchPattern(1));
   g.FillRectangle(b, SX + 2, SY + 2, W - 2, H - 2);
   b.Dispose();
}
Notice the comments. If I draw the converted bitmap as an image, it draws properly, in Yellow and Red. But, when I use the SAME BITMAP for a TextureBrush, the rectangle is filled in Black & White!

I have looked and looked, and have found no solution or explanation for this behavior. Perhaps some guru out there can provide me one?

P.S. If I uncomment the 'MakeTransparent' call above, the background goes to transparent, but the foreground pixels remain Black.

ADDITIONAL INFO:

By the way, when I uncomment the 'MakeTransparent' call above, the bitmap drawn as an image ALSO shows up with the foreground pixels Black! More fodder for the fire!