Link to home
Start Free TrialLog in
Avatar of GGuzdziol
GGuzdziolFlag for Luxembourg

asked on

GDI+ - refresh too slow

Hi,

I have an application (managed c++) that works on two dimensional array of integers. Its size is user-defined, but let's assume it's 500x500. Each value represents different object - assume there are about 11 distinct values (0 - empty field and 1..10 - kinds of objects). I want to visualize it. So far I set up Graphics (g = this->CreateGraphics()) Pen (p) and SolidBrush (b) objects. Then I put loop
                         for(int i = 0; i < lattice->board->sizeX(); i++) {
                               for(int j = 0; j < lattice->board->sizeY(); j++) {
                                     if(lattice->board->getPlankton(i, j) != nullptr) {
                                          b->Color = lattice->board->getPlankton(i, j)->printColor();
                                          g->FillRectangle(b, offset_x + pix_size*i, offset_y + pix_size*j, pix_size, pix_size);
                                     }
                               }
                         }
Everything is neat and nice, as desired.

The problem is that this is simulation of integers in this array...when theirs quantity (!= 0) gets higher, refreshing image gets really slow. I can see how it goes column-by-column...and it's unacceptable for me.
I've already tried to set up double buffering with
                         this->SetStyle(static_cast<ControlStyles>(ControlStyles::DoubleBuffer |
                              ControlStyles::UserPaint |
                              ControlStyles::AllPaintingInWmPaint),
                              true);
                         this->UpdateStyles();
but this doesn't help me.

The questions are:
(1) what can I do to improve my performance?
or
(2) I do not insist on drawing it like that, I just need to have this array displayed in any way. Maybe there is better way to accompish that?

Thanks,
Grzegorz
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GGuzdziol

ASKER

Perfectly, master! :-)