Question

I'm painting this object in C# using GDI and I need to have precise pixel painting. However, this is not working... I don't know if it matters but the object I'm painting is a ToolStrip, I'm doing a custom ToolStrip render.

I drew a horizontal blue line at y-pixel 1, than a yellow one at y-pixel 2 than a red one at y-pixel 3. These are not real colors it's just for me to see better.

Like this:

Color cTop1 = Color.FromArgb(255, Color.Blue);
Color cTop2 = Color.FromArgb(255, Color.Yellow);
Color cTop3 = Color.FromArgb(255, Color.Red);

g.DrawLine(new Pen(cTop1), 0, 1, aBounds.Width, 1);
g.DrawLine(new Pen(cTop2), 0, 2, aBounds.Width, 2);
g.DrawLine(new Pen(cTop3), 0, 3, aBounds.Width, 3);

Than, at y-pixel 4 I started filling a rectangle with the LinearGradientBrush like this:

Rectangle rTop = new Rectangle(0, 3, aBounds.Width, (aBounds.Height / 2) - 4);

Color cTop = Color.FromArgb(245, Color.White);
Color cBottom = Color.FromArgb(222, Color.White);

LinearGradientBrush tGradient = new LinearGradientBrush(rTop, cTop, cBottom, LinearGradientMode.Vertical);
g.FillRectangle(tGradient, rTop);

The problem is that the gradient is painting above the red line. The blue and yellow ones are ok, but the red line, which should be RGB=255,0,0, it's in fact RGB=255,111,111.

I can't understand why... I've played in SmoothingMode, InterpolationMode, CompositionMode, CompositionQuality but I just can't make it right...

Any ideias?

Was it helpful?

Solution

It's possible that the brush is being wrapped and what you are seeying is the oposite colour "bleeding" in.

Try and set the wrapmode to

brush.WrapMode = Drawing2D.WrapMode.TileFlipXY
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top