Drawing bitmaps

G

Guest

Hello everybody.

I am drawing a country map that consists of 149 municipality bitmaps, each
around 25 Kb. I draw it onto the in-memory bitmap, then draw it on the
picture box.
I use C++, but anyways if I were using the C# the question would be the same.
And here is the problem: it takes 700 ms to draw it, and anything above 300
ms is noticable by the human eye.
So, is there any technique that I could use to actually keep the bitmaps in
the memory oince I load them (like in memory stream, or an ArrayList of
objects, or something), so to avoid the issues of losing time on IO
operations?
Is there like a general guideline to follow when it comes to this?

Thanks.
 
L

Lloyd Dupont

Hello everybody.
Hi!
I am drawing a country map that consists of 149 municipality bitmaps, each
around 25 Kb. I draw it onto the in-memory bitmap, then draw it on the
picture box. Cool!

I use C++, but anyways if I were using the C# the question would be the
same.
And here is the problem: it takes 700 ms to draw it, and anything above
300
ms is noticable by the human eye.
I would say that even >50ms is perceptible
So, is there any technique that I could use to actually keep the bitmaps
in
the memory oince I load them (like in memory stream, or an ArrayList of
objects, or something), so to avoid the issues of losing time on IO
operations?
what about keeping a reference to them?
perhaps in a structure with some location information. and then store the
structures in an array?

I'm a bit confused because this seems overtly simple and evident... do you
know you could have instance variable?
Say in your form?
Is there like a general guideline to follow when it comes to this?
Well usually there is some some instance variable ins some relevant class
which last as long as the problem.
Maybe instance variable in your form.....
 
R

Richard Grimes

Mike said:
Hello everybody.

I am drawing a country map that consists of 149 municipality bitmaps,
each around 25 Kb. I draw it onto the in-memory bitmap, then draw it
on the picture box.

You have to determine what is taking the time. Are you loading the
bitmaps from disk before drawing them to the in-memory bitmap? You
really need to do some profiling to see what is taking the time. Without
seeing the code it is not possible to give an accurate solution, but
here's some stuff to check:

- are the bitmaps loaded from disk, if so, then try to pre-load them,
perhaps using a separate thread kicked off from the form constructor so
that they are all loaded before the routine to draw them is run (you'll
need inter-thread communication here).
- are all the bitmaps compatible with the in-memory bitmap, ie the same
colour depth?
- you say the bitmaps are 'municipality bitmaps' which presumably are
not at exact intersections of a grid and are irregular in size, in which
case, check the code that decides where in the in-memory bitmap each
'municipality bitmap' is drawn.
So, is there any technique that I could use to actually keep the
bitmaps in the memory oince I load them (like in memory stream, or an
ArrayList of objects, or something), so to avoid the issues of losing
time on IO operations?

Yes. ArrayList is fine:

string[] names = {"one.bmp", "two.bmp", "three.bmp"};
ArrayList bitmaps = new ArrayList();
foreach(string name in names)
{
bitmaps.Add(new Bitmap(name));
}

// draw image two.bmp at 100, 200:
graphics.DrawImage((Image)bitmaps[1], 100, 200);
Is there like a general guideline to follow when it comes to this?

Profiling is the best course. Also check your loops. The IO operation
that is the slowest is disk IO, so be careful about any code that
accesses files.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top