Quickly drawing an image line by line

I need to draw an Image line by line, each line arrives as an custom
event that's posted from other thread (like a scanner). What's the most
efficient way to do it? I'm new to wxPython and all these options of
wxDCs, wxBitmaps and wxImage are a little confusing.

I'm using Python 2.3.3 and wxPython 2.4.2.4.

Thanks in advance for any help.

···

--
Paulo Neves <neves@gisplan.com.br>
Gisplan

Paulo Neves wrote:

I need to draw an Image line by line, each line arrives as an custom
event that's posted from other thread (like a scanner). What's the most
efficient way to do it? I'm new to wxPython and all these options of
wxDCs, wxBitmaps and wxImage are a little confusing.

Create a bitmap large enough for the final image, select the bitmap into a wxMemoryDC, draw the new line to the proper location in that DC, then Blit the new line from that DC to the DC for the Window you are displaying the image in. When the window needs repainting, just Blit the whole bitmap.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Paulo Neves wrote:
> I need to draw an Image line by line, each line arrives as an custom
> event that's posted from other thread (like a scanner). What's the most
> efficient way to do it? I'm new to wxPython and all these options of
> wxDCs, wxBitmaps and wxImage are a little confusing.

Create a bitmap large enough for the final image, select the bitmap into
a wxMemoryDC, draw the new line to the proper location in that DC, then
Blit the new line from that DC to the DC for the Window you are
displaying the image in. When the window needs repainting, just Blit
the whole bitmap.

My preferred way of doing the above is similar, but I would
use an idle handler in the gui thread to do the actual drawing
into the bitmap (call Refresh after updating the backing
bitmap). This is especially important if running on slower machines
or where there is the possibility of the data overwhelming
the gui thread.

True story: In the early days of BitPim, it would get slower
and slower until becoming almost useless while talking to a
phone. The reason was because the communications thread
was sending log messages to the gui thread as events, and
the gui thread was then calling AppendText on a TextCtrl.
It appears that TextCtrl.AppendText reparses all the text
or does something similar based on the size of all of the
text, not just what is being added.

This meant it took longer and longer to append each log
entry. I fixed it by accumulating the log text in
the gui thread, and calling TextCtrl.AppendText in
an OnIdle handler. It is now nice and zippy no matter
how much logging is going on.

Roger