I am trying to continuously visualize an image in a panel with C++ using Visual Studio 2008. So, I have the following code which basically reiterates the Paint event continuously.
getNewImage(img_paint); // function for getting new image
DrawImage(img_paint,pixels, pixels,1,0,false,panel1 ->Width, panel1 -> Height,e-Graphics); // function for painting the image
panel1->Invalidate(); // reiterate the Paint event
}
The problem here is that when I call Invalidate() function the panel disappears for a brief time then it gets drawn with DrawImage() function. Since getNewImage() method is very fast, I see a lot of what I believe is called as "flickering" (lots of flashes in the screen). Right now I manage this by adding Sleep(400); to the last line so that it flickers less, but this is not an optimum method as you can imagine.
When I searched the web I saw some stuff about "double buffering" but I couldn't implement them. The solutions I found are usually for C# and they cause me errors when I copy-paste to my code.
The only thing I managed to do without an error was to add "this->DoubleBuffered = true;" to the following part, but it did not change anything:
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
this->DoubleBuffered = true;
}
I will really appreciate if you have any idea on how I can fix this problem easily.
I can't help you with this because it's too advanced for me, but you can try putting this in the General section, maybe you'll get more response there. Also, code tags might help people help you.