Masked bitmap from bitmap

Discussion in 'Python' started by Gandalf, Jan 29, 2004.

  1. Gandalf

    Gandalf Guest

    Hi Gurus! Here is a problem with wxPython. I would like to load bitmaps
    and create a mask
    for them at once. Here is my idea: the mask colour for the bitmap should
    be the colour of
    the pixel in the top left corner. (The same way Delphi does with
    TImageList.) E.g. the
    bitmap should be transparent everywhere with the same colour. I read the
    and I could not find an easy way to do this. Here is what I have tried:

    1. Create a wxIcon directly (which is a wxBitmap, I only need a masked

    This does not suit for me, since I need to load bitmaps on all
    platforms. wxIcon cannot handle the BMP format on all platforms.
    This is from the docs (about the type parameter of wx.Icon):

    >wxBITMAP_TYPE_ICO Load a Windows icon file.
    >wxBITMAP_TYPE_ICO_RESOURCE Load a Windows icon from the resource

    >wxBITMAP_TYPE_GIF Load a GIF bitmap file.
    >wxBITMAP_TYPE_XBM Load an X bitmap file.
    >wxBITMAP_TYPE_XPM Load an XPM bitmap file.
    >The validity of these flags depends on the platform and wxWindows

    configuration. If all possible wxWindows settings are used, the Windows
    platform supports ICO file, ICO resource, XPM data, and XPM file. Under
    wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG
    file. Under wxMotif, the available formats are XBM data, XBM file, XPM
    data, XPM file.

    wxIcon cannot handle BMP on the Windows platform so I cannot use wxIcon.

    2. Load wxBitmap and use wxIcon.CopyFromBitmap.

    Is not okay. This is from the docs:

    >Copies bmp bitmap to this icon. Under MS Windows the bitmap must have

    mask colour set.

    Back to the stove: once I have a bitmap with a mask, I do not really
    need a wxIcon. :-( For most platforms, this solution would be fine but
    not on M$ Windows.

    3. Load a bitmap and specify the mask by hand. That would be great.
    Unfortunately, I cannot get the colour of the top left pixel. There is
    no such method, or I could not find it :-/ Even if there were one, I
    would had created the mask by hand, in Python. I cannot set pixels'
    colours (no method for that). And of course, this would be very slow.

    4. Load the bitmap in PIL, create the mask by hand, save the mask into a
    different file/object, load the bitmap and the saved mask into different
    objects, finally combine them. Oh yeah, I can imagine this would work.
    But it is too difficult and it would be very very very slow. There must
    be a better way.

    Please note that I do not want to use C/SWIG or any external tool. I
    would like to use pure Python with wxPython if possible. Can somebody
    help me?
    A code fragment or a link would be great.

    Thanks in advance,

    Gandalf, Jan 29, 2004
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. |{evin
    Nov 18, 2003
  2. =?Utf-8?B?bWV0cmlkZXZraw==?=

    Masked Edit Control

    =?Utf-8?B?bWV0cmlkZXZraw==?=, Dec 3, 2004, in forum: ASP .Net
    Steve C. Orr [MVP, MCSD]
    Dec 3, 2004
  3. =?Utf-8?B?ZGF2aWQ=?=
    Ken Cox [Microsoft MVP]
    Apr 19, 2005
  4. Dynamo
  5. xqggz
    Victor Bazarov
    Jun 19, 2007

Share This Page