prevent screen flicker

linesh

Active member
Joined
Oct 14, 2004
Messages
32
Location
Washington D.C.
Hi All,
I am trying to paint a sequence of images on a usercontrol using the CSharp Graphics() object and this usercontrol is embedded in a windows forms application. The image painting part of it works fine but the screen(monitor) seems to flicker every once in a while. It looks like its being forced to refresh periodically by the application.

Here is the code:
Bitmap bm = new Bitmap(BMImageBuffer);
GLiveGraphics.DrawImage(bm,destRect,srcRect,GraphicsUnit.Pixel);


The drawing in continuously done by a drawing thread..at the rate of 10-15 FPS.

I tried setting double-buffering options-it only prevented flicker inside the control but not the entire screen refresh. IS there anyway to prevent a monitor refresh()?

Thanks in advance
Linesh
 
linesh said:
Hi All,
I am trying to paint a sequence of images on a usercontrol using the CSharp Graphics() object and this usercontrol is embedded in a windows forms application. The image painting part of it works fine but the screen(monitor) seems to flicker every once in a while. It looks like its being forced to refresh periodically by the application.

Here is the code:
Bitmap bm = new Bitmap(BMImageBuffer);
GLiveGraphics.DrawImage(bm,destRect,srcRect,GraphicsUnit.Pixel);


The drawing in continuously done by a drawing thread..at the rate of 10-15 FPS.

I tried setting double-buffering options-it only prevented flicker inside the control but not the entire screen refresh. IS there anyway to prevent a monitor refresh()?

Thanks in advance
Linesh
I will assume you are overriding the OnPaint method of the control (if your not you should probably think about doing so), if this is teh case you should also override OnPaintBackground removing the base.OnPaintBackground(e) line of code to prevent the background from being drawn (if you dont paint the entire control you can always do a Graphics.Clear() as part of the OnPaint method). This is in my experience the biggest cause of flickering when working with GDI+.
 
Cags,
Thanks for the response. No, I am not really using the OnPaint control. I will see if I can use it. I just have the function overrriden, but there is no code inside it. Same for OnPaintBackground().

//OnPaint in Overridden here so that it doesnt call paint
protected override void OnPaint(PaintEventArgs pevent)
{
}

//OnPaintBackground in Overridden here so that it doesnt call
//paintbackground to clear the background
protected override void OnPaintBackground(PaintEventArgs pevent)
{
}


I do paint over the entire control. I also tried putting a picturebox into the control,setting its dock property to Fill and painting over it, but i get the same effect.

You mentioned calling Graphics.Clear(). In this case, where should i try adding Graphics.Clear()?
 
I finally found the cause of the problem. It was the "Hardware Acceleration" settings in Windows (under Display Settings). It was set to "Full". Changing it one of the medium settings stopped the flicker completely. The problem occurs more frequently on systems with the NVidia display adapters.
 
Having users turn down their graphics acceleration is hardly a realistic solution. Unless there is a real good reason, this should always be set to full. Otherwise, it can adversely affect the performance of some other applications.

With this kind of drawing, the most likely suspect, as Cags pointed out, is redrawing that is happening that you dont want and dont realize is happening.

Override painting events. Change attribute flags. Intercept messages. Maybe in this particular situation it isnt a big deal, but your solution should, if at all possible, not require that a user change advanced settings, and preferably, not require that any settings be changed.
 
Back
Top