views:

49

answers:

1

I have a Bitmap called "buffer" to which I

  1. Paint another image (using DrawImage)
  2. 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);
A: 

I noticed you don't create the Graphics object in a using block. Could Dispose() be needed to fully flush it?

using (Graphics bufferG = Graphics.FromImage(buffer)
{
...
}
bbudge
Calling Dispose manually does not help, unfortunately.
kpozin