By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

Drawing bitmaps

P: n/a
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.

Dec 10 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> 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.....

Thanks.

Dec 10 '05 #2

P: n/a
Mike wrote:
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
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 11 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.