Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
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 don't 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+.

Anybody looking for a graduate programmer (Midlands, England)?
Posted

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()?

  • 2 months later...
Posted
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.
  • Leaders
Posted

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 don't want and don't realize is happening.

 

Override painting events. Change attribute flags. Intercept messages. Maybe in this particular situation it isn't 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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...