linesh Posted March 31, 2006 Posted March 31, 2006 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 Quote
Cags Posted March 31, 2006 Posted March 31, 2006 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+. Quote Anybody looking for a graduate programmer (Midlands, England)?
linesh Posted March 31, 2006 Author Posted March 31, 2006 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()? Quote
Cags Posted March 31, 2006 Posted March 31, 2006 Take a look at the example I give in this post, its possible it will help you. If it doesn't then I'm misunderstanding your problem. http://www.xtremedotnettalk.com/showthread.php?t=95886&highlight=buffer Quote Anybody looking for a graduate programmer (Midlands, England)?
linesh Posted June 13, 2006 Author Posted June 13, 2006 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. Quote
Administrators PlausiblyDamp Posted June 13, 2006 Administrators Posted June 13, 2006 Did you try updating the drivers etc. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Leaders snarfblam Posted June 13, 2006 Leaders Posted June 13, 2006 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.