an Image

Mel Wilson mwilson at the-wire.com
Sat Aug 7 18:40:48 EDT 2004


In article <18282ecb.0407282040.231e5766 at posting.google.com>,
mefjr75 at hotmail.com (M.E.Farmer) wrote:
>justin__devine at hotmail.com (JDevine) wrote in message news:<f9d01b73.0407271254.427a271a at posting.google.com>...
>> I am going through the painfull process of learning wxPython.  Sincer
>> there is nearly no documentation, I am learning from the demos.
>> Unfortunately, I have realized these demos do some specialized
>> importing and that all the imports are not applicable.  Specifially,
>> All I want to do now is insert a bmp I have drawn into a windows
>> application.  The image clases from the demos are completely
>> unexplanatory about how to do this.  The "images" module that is
>> imported has custom functions for calling a specific set of images
>> such as GetTest2Bitmap, which does not help me at all.  Please help me
>> understand this.

>Maybe this will help you.
>
># SimpleImage ver 1.0
># by M.E.Farmer Jr. 2003
># Utilizes the new wx namespace
># usage: python SimpleImage.py image.jpg
>[ ... ]
>    pix = wx.Image(sys.argv[1], wx.BITMAP_TYPE_ANY).ConvertToBitmap()
>[ ... ]
>    st = wx.StaticBitmap(frame, -1, pix, pos=(1,1),
>                         size=wx.Size(pix.GetWidth(),pix.GetHeight()))

   You can also with a little more difficulty write straight
to the window..  Below is a fragment from __init__ of a
wx.Frame descendant.  (It's straight from working code but I
haven't tested it independently.)


        w, h = self.GetClientSizeTuple()
        bmp = wx.EmptyBitmap (w, h)
        mdc = wx.MemoryDC()
        if bmp.LoadFile ("sweeper.bmp", wx.BITMAP_TYPE_BMP):
            mdc.SelectObject (bmp)
            wx.ClientDC (self).Blit (0,0, w,h, mdc, 0,0)


   The complication with such techniques is that you need to
coordinate a lot of different objects..  Frame, Bitmap, DC..
and look up the separate documentation on those guys.. to
get any work done.  Also not shown is the paint routine that
replays that Blit operation after an EVT_PAINT.  Just for
what it's worth because I was just working on this.

        Regards.    Mel.



More information about the Python-list mailing list