I have a Bitmap called "buffer" to which I
- Paint another image (using DrawImage)
- Paint a partially transparent gradient (using a LinearGradientBrush)
I call Flush(FlushIntention.Sync)
on the buffer's Graphics object after each of those steps. I then paint the contents of the buffer onto an on-screen control.
However, while debugging, I noticed that sometimes the buffer doesn't have a gradient painted on. What can be causing the 2nd paint operation to be skipped even when I'm explicitly calling a synchronized Flush command?
Is there any workaround?
EDIT: Code sample
Bitmap background = ....;
Bitmap buffer = new Bitmap(100, 100);
Rectangle bufferBounds = new Rectangle(0, 0, buffer.Width, buffer.Height);
Graphics bufferG = Graphics.FromImage(buffer);
// First step
bufferG.DrawImageUnscaled(background, 0, 0);
bufferG.Flush(FlushIntention.Sync);
// Second step
LinearGradientBrush lgb = new LinearGradientBrush(bufferBounds,
maxColor, minColor, LinearGradientMode.Vertical);
bufferG.FillRectangle(lgb, bufferBounds);
bufferG.Flush(FlushIntention.Sync);