.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2020 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.Bitmap:

==========================================================================================================================================
|phoenix_title|  **wx.Bitmap**
==========================================================================================================================================

This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or colour with alpha channel support.          

If you need direct access the bitmap data instead going through drawing to it using :ref:`wx.MemoryDC`  you need to use the :ref:`PixelData`  class (either NativePixelData for ``RGB`` bitmaps or AlphaPixelData for bitmaps with an additionally alpha channel). 

Note that many :ref:`wx.Bitmap`  functions take a `type`  parameter, which is a value of the :ref:`wx.BitmapType`  enumeration. The validity of those values depends however on the platform where your program is running and from the wxWidgets configuration. If all possible wxWidgets settings are used:

- wxMSW supports ``BMP`` and ``ICO`` files, ``BMP`` and ``ICO`` resources; 
- wxGTK supports any file supported by gdk-pixbuf; 
- Mac supports ``PICT`` resources; 
- X11 supports XPM files, XPM data, ``XBM`` data; 




In addition, :ref:`wx.Bitmap`  can load and save all formats that :ref:`wx.Image`  can; see :ref:`wx.Image`  for more info. Of course, you must have loaded the :ref:`wx.Image`  handlers (see :ref:`wx.InitAllImageHandlers`  and :meth:`wx.Image.AddHandler` ). Note that all available BitmapHandlers for a given wxWidgets port are automatically loaded at startup so you won't need to use :meth:`wx.Bitmap.AddHandler` . 

More on the difference between :ref:`wx.Image`  and :ref:`wx.Bitmap`: :ref:`wx.Image`  is just a buffer of ``RGB`` bytes with an optional buffer for the alpha bytes. It is all generic, platform independent and image file format independent code. It includes generic code for scaling, resizing, clipping, and other manipulations of the image data. OTOH, :ref:`wx.Bitmap`  is intended to be a wrapper of whatever is the native image format that is quickest/easiest to draw to a DC or to be the target of the drawing operations performed on a :ref:`wx.MemoryDC`. By splitting the responsibilities between Image/wxBitmap like this then it's easier to use generic code shared by all platforms and image types for generic operations and platform specific code where performance or compatibility is needed. 







         



.. seealso:: :ref:`Bitmaps and Icons <bitmaps and icons>`, :ref:`Supported Bitmap File Formats <supported bitmap file formats>`, :meth:`wx.DC.Blit` , :ref:`wx.Icon`, :ref:`wx.Cursor`, :ref:`wx.MemoryDC`, :ref:`wx.Image`, :ref:`PixelData`    







|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>Bitmap</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.Bitmap_inheritance.png" alt="Inheritance diagram of Bitmap" usemap="#dummy" class="inheritance"/></center>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.Bitmap.html" title="wx.Bitmap" alt="" coords="15,160,107,189"/> <area shape="rect" id="node2" href="wx.GDIObject.html" title="wx.GDIObject" alt="" coords="5,83,116,112"/> <area shape="rect" id="node3" href="wx.Object.html" title="wx.Object" alt="" coords="17,5,104,35"/> </map> 
   </p>
   </div>

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.Bitmap.__init__`                                                      Default constructor.
:meth:`~wx.Bitmap.ConvertToDisabled`                                             Returns disabled (dimmed) version of the bitmap.
:meth:`~wx.Bitmap.ConvertToImage`                                                Creates an image from a platform-dependent bitmap.
:meth:`~wx.Bitmap.CopyFromBuffer`                                                Copy data from a buffer object to replace the bitmap pixel data.
:meth:`~wx.Bitmap.CopyFromIcon`                                                  Creates the bitmap from an icon.
:meth:`~wx.Bitmap.CopyToBuffer`                                                  Copy pixel data to a buffer object.  See :meth:`~Bitmap.CopyFromBuffer` for buffer
:meth:`~wx.Bitmap.Create`                                                        Creates a fresh bitmap.
:meth:`~wx.Bitmap.CreateScaled`                                                  Create a bitmap with a scale factor.
:meth:`~wx.Bitmap.CreateWithDIPSize`                                             Create a bitmap specifying its size in DPI-independent pixels and the scale factor to use.
:meth:`~wx.Bitmap.FromBuffer`                                                    Creates a :class:`wx.Bitmap` from in-memory data.  The data parameter
:meth:`~wx.Bitmap.FromBufferAndAlpha`                                            Creates a :class:`wx.Bitmap` from in-memory data.  The data and alpha
:meth:`~wx.Bitmap.FromBufferRGBA`                                                Creates a :class:`wx.Bitmap` from in-memory data.  The data parameter
:meth:`~wx.Bitmap.FromPNGData`                                                   Like :meth:`~Bitmap.NewFromPNGData` but with a simpler API accepting a Python
:meth:`~wx.Bitmap.FromRGBA`                                                      Creates a new empty 32-bit :class:`wx.Bitmap` where every pixel has been
:meth:`~wx.Bitmap.GetDIPSize`                                                    Returns the size of bitmap in DPI-independent units.
:meth:`~wx.Bitmap.GetDepth`                                                      Gets the colour depth of the bitmap.
:meth:`~wx.Bitmap.GetHandle`                                                     MSW-only method to fetch the windows handle for the bitmap.
:meth:`~wx.Bitmap.GetHeight`                                                     Returns the height of the bitmap in physical pixels.
:meth:`~wx.Bitmap.GetLogicalHeight`                                              Returns the height of the bitmap in logical pixels.
:meth:`~wx.Bitmap.GetLogicalSize`                                                Returns the size of the bitmap in logical pixels.
:meth:`~wx.Bitmap.GetLogicalWidth`                                               Returns the width of the bitmap in logical pixels.
:meth:`~wx.Bitmap.GetMask`                                                       Gets the associated mask (if any) which may have been loaded from a file or set for the bitmap.
:meth:`~wx.Bitmap.GetPalette`                                                    Gets the associated palette (if any) which may have been loaded from a file or set for the bitmap.
:meth:`~wx.Bitmap.GetScaleFactor`                                                Returns the scale factor of this bitmap.
:meth:`~wx.Bitmap.GetScaledHeight`                                               Returns the height of the bitmap in logical pixels.
:meth:`~wx.Bitmap.GetScaledSize`                                                 Returns the size of the bitmap in logical pixels.
:meth:`~wx.Bitmap.GetScaledWidth`                                                Returns the width of the bitmap in logical pixels.
:meth:`~wx.Bitmap.GetSize`                                                       Returns the size of the bitmap in physical pixels.
:meth:`~wx.Bitmap.GetSubBitmap`                                                  Returns a sub bitmap of the current one as long as the rect belongs entirely to the bitmap.
:meth:`~wx.Bitmap.GetWidth`                                                      Returns the width of the bitmap in physical pixels.
:meth:`~wx.Bitmap.HasAlpha`                                                      Returns ``True`` if the bitmap has an alpha channel.
:meth:`~wx.Bitmap.IsOk`                                                          Returns ``True`` if bitmap data is present.
:meth:`~wx.Bitmap.LoadFile`                                                      Loads a bitmap from a file or resource.
:meth:`~wx.Bitmap.NewFromPNGData`                                                Loads a bitmap from the memory containing image data in ``PNG`` format.
:meth:`~wx.Bitmap.Rescale`                                                       Rescale the given bitmap to the requested size.
:meth:`~wx.Bitmap.ResetAlpha`                                                    Remove alpha channel from the bitmap.
:meth:`~wx.Bitmap.SaveFile`                                                      Saves a bitmap in the named file.
:meth:`~wx.Bitmap.SetDepth`                                                      
:meth:`~wx.Bitmap.SetHandle`                                                     MSW-only method to set the windows handle for the bitmap.
:meth:`~wx.Bitmap.SetHeight`                                                     
:meth:`~wx.Bitmap.SetMask`                                                       Sets the mask for this bitmap.
:meth:`~wx.Bitmap.SetMaskColour`                                                 Create a mask for this bitmap based on the pixels with the given colour.
:meth:`~wx.Bitmap.SetPalette`                                                    Sets the associated palette.
:meth:`~wx.Bitmap.SetScaleFactor`                                                Sets the bitmap scale factor.
:meth:`~wx.Bitmap.SetSize`                                                       Set the bitmap size (does not alter the existing native bitmap data or image size).
:meth:`~wx.Bitmap.SetWidth`                                                      
:meth:`~wx.Bitmap.UseAlpha`                                                      Enable or disable use of alpha channel in this bitmap.
:meth:`~wx.Bitmap.__bool__`                                                      
:meth:`~wx.Bitmap.__nonzero__`                                                   
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.Bitmap.DIPSize`                                                       See :meth:`~wx.Bitmap.GetDIPSize`
:attr:`~wx.Bitmap.Depth`                                                         See :meth:`~wx.Bitmap.GetDepth` and :meth:`~wx.Bitmap.SetDepth`
:attr:`~wx.Bitmap.Handle`                                                        See :meth:`~wx.Bitmap.GetHandle` and :meth:`~wx.Bitmap.SetHandle`
:attr:`~wx.Bitmap.Height`                                                        See :meth:`~wx.Bitmap.GetHeight` and :meth:`~wx.Bitmap.SetHeight`
:attr:`~wx.Bitmap.LogicalHeight`                                                 See :meth:`~wx.Bitmap.GetLogicalHeight`
:attr:`~wx.Bitmap.LogicalSize`                                                   See :meth:`~wx.Bitmap.GetLogicalSize`
:attr:`~wx.Bitmap.LogicalWidth`                                                  See :meth:`~wx.Bitmap.GetLogicalWidth`
:attr:`~wx.Bitmap.Mask`                                                          See :meth:`~wx.Bitmap.GetMask` and :meth:`~wx.Bitmap.SetMask`
:attr:`~wx.Bitmap.Palette`                                                       See :meth:`~wx.Bitmap.GetPalette` and :meth:`~wx.Bitmap.SetPalette`
:attr:`~wx.Bitmap.ScaleFactor`                                                   See :meth:`~wx.Bitmap.GetScaleFactor` and :meth:`~wx.Bitmap.SetScaleFactor`
:attr:`~wx.Bitmap.ScaledHeight`                                                  See :meth:`~wx.Bitmap.GetScaledHeight`
:attr:`~wx.Bitmap.ScaledSize`                                                    See :meth:`~wx.Bitmap.GetScaledSize`
:attr:`~wx.Bitmap.ScaledWidth`                                                   See :meth:`~wx.Bitmap.GetScaledWidth`
:attr:`~wx.Bitmap.Size`                                                          See :meth:`~wx.Bitmap.GetSize` and :meth:`~wx.Bitmap.SetSize`
:attr:`~wx.Bitmap.Width`                                                         See :meth:`~wx.Bitmap.GetWidth` and :meth:`~wx.Bitmap.SetWidth`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.Bitmap(GDIObject)

   **Possible constructors**::

       Bitmap()
       
       Bitmap(bitmap)
       
       Bitmap(bits, width, height, depth=1)
       
       Bitmap(width, height, depth=BITMAP_SCREEN_DEPTH)
       
       Bitmap(sz, depth=BITMAP_SCREEN_DEPTH)
       
       Bitmap(width, height, dc)
       
       Bitmap(name, type=BITMAP_TYPE_ANY)
       
       Bitmap(img, depth=BITMAP_SCREEN_DEPTH)
       
       Bitmap(img, dc)
       
       Bitmap(listOfBytes)
       
   
   This class encapsulates the concept of a platform-dependent bitmap,
   either monochrome or colour or colour with alpha channel support.



   .. method:: __init__(self, *args, **kw)



      |overload| Overloaded Implementations:

      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self)`
      
      Default constructor.                  
      
      Constructs a bitmap object with no data; an assignment or another member function such as :meth:`Create`   or :meth:`LoadFile`   must be called subsequently.                   
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, bitmap)`
      
      Copy constructor, uses :ref:`reference counting <reference counting>`.                  
      
      To make a real copy, you can use: 
      
      ::
      
                  newBitmap = oldBitmap.GetSubBitmap(
                                        wx.Rect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()))
      
                       
      
      
      :param `bitmap`: 
      :type `bitmap`: wx.Bitmap
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, bits, width, height, depth=1)`
      
      Creates a bitmap from the given array `bits`.                  
      
      You should only use this function for monochrome bitmaps (depth 1) in portable programs: in this case the bits parameter should contain an ``XBM`` image. 
      
      For other bit depths, the behaviour is platform dependent: under Windows, the data is passed without any changes to the underlying CreateBitmap() API. Under other platforms, only monochrome bitmaps may be created using this constructor and :ref:`wx.Image`  should be used for creating colour bitmaps from static data. 
      
      
      
      
      :param `bits`: Specifies an array of pixel values.   
      :type `bits`: string
      :param `width`: Specifies the width of the bitmap.   
      :type `width`: int
      :param `height`: Specifies the height of the bitmap.   
      :type `height`: int
      :param `depth`: Specifies the depth of the bitmap. If this is omitted, then a value of 1 (monochrome bitmap) is used.  
      :type `depth`: int
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, width, height, depth=BITMAP_SCREEN_DEPTH)`
      
      Creates a new bitmap.                  
      
      A depth of ``BITMAP_SCREEN_DEPTH``  indicates the depth of the current screen or visual. 
      
      Some platforms only support 1 for monochrome and ``BITMAP_SCREEN_DEPTH``  for the current colour setting. 
      
      A depth of 32 including an alpha channel is supported under MSW, Mac and GTK+. 
      
      
      
      
      :param `width`: The width of the bitmap in pixels, must be strictly positive.   
      :type `width`: int
      :param `height`: The height of the bitmap in pixels, must be strictly positive.   
      :type `height`: int
      :param `depth`: The number of bits used to represent each bitmap pixel.   
      :type `depth`: int
      
      
      
      
      
      
      
      
                        
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, sz, depth=BITMAP_SCREEN_DEPTH)`
      
      This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.                  
      
      
      :param `sz`: 
      :type `sz`: wx.Size
      :param `depth`: 
      :type `depth`: int
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, width, height, dc)`
      
      Create a bitmap compatible with the given DC, inheriting its magnification factor.                  
      
      
      
      
      :param `width`: The width of the bitmap in pixels, must be strictly positive.   
      :type `width`: int
      :param `height`: The height of the bitmap in pixels, must be strictly positive.   
      :type `height`: int
      :param `dc`: DC from which the scaling factor is inherited  
      :type `dc`: wx.DC
      
      
      
      
      
      
      
      
                        
      
      
      
      .. versionadded:: 4.1/wxWidgets-3.1.7  
         (previously available only in wxMSW and wxOSX ports).   
      
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, name, type=BITMAP_TYPE_ANY)`
      
      Loads a bitmap from a file or resource.                  
      
      
      
      
      :param `name`: This can refer to a resource name or a filename under MS Windows and X. Its meaning is determined by the  `type`  parameter.   
      :type `name`: string
      :param `type`: May be one of the :ref:`wx.BitmapType`  values and indicates which type of bitmap should be loaded. See the note in the class detailed description. Note that the ``BITMAP_DEFAULT_TYPE`` constant has different value under different wxWidgets ports. See the bitmap.h header for the value it takes for a specific port.  
      :type `type`: wx.BitmapType
      
      
      
      
      
      
                        
      
      
      
      .. seealso:: :meth:`LoadFile`     
      
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, img, depth=BITMAP_SCREEN_DEPTH)`
      
      Creates this bitmap object from the given image.                  
      
      This has to be done to actually display an image as you cannot draw an image directly on a window. 
      
      The resulting bitmap will use the provided colour depth (or that of the current system if depth is ``BITMAP_SCREEN_DEPTH``) which entails that a colour reduction may take place. 
      
      On Windows, if there is a palette present (set with SetPalette), it will be used when creating the :ref:`wx.Bitmap`  (most useful in 8-bit display mode). On other platforms, the palette is currently ignored. 
      
      
      
      
      :param `img`: Platform-independent :ref:`wx.Image`  object.   
      :type `img`: wx.Image
      :param `depth`: Specifies the depth of the bitmap. If this is omitted, the display depth of the screen is used.   
      :type `depth`: int
      
      
      
      
      
      
                        
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, img, dc)`
      
      Creates a bitmap compatible with the given DC from the given image.                  
      
      This constructor initializes the bitmap with the data of the given image, which must be valid, but inherits the scaling factor from the given device context instead of simply using the default factor of 1. 
      
      
      
      
      :param `img`: Platform-independent :ref:`wx.Image`  object.   
      :type `img`: wx.Image
      :param `dc`: DC from which the scaling factor is inherited  
      :type `dc`: wx.DC
      
      
      
      
      
      
                        
      
      
      
      .. versionadded:: 4.1/wxWidgets-3.1.7  
         (previously this constructor overload was only available in wxMSW port)   
      
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, listOfBytes)`
      
      Construct a Bitmap from a list of strings formatted as XPM data.  
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`






   .. method:: ConvertToDisabled(self, brightness=255)

      Returns disabled (dimmed) version of the bitmap.                  

      This method is not available when  ``USE_IMAGE == 0`` . 

                


      :param `brightness`: 
      :type `brightness`: int




      :rtype: :ref:`wx.Bitmap`







      .. versionadded:: 2.9.0 
     








   .. method:: ConvertToImage(self)

      Creates an image from a platform-dependent bitmap.                  

      This preserves mask information so that bitmaps and images can be converted back and forth without loss in that respect.                  

      :rtype: :ref:`wx.Image`








   .. method:: CopyFromBuffer(self, data, format=BitmapBufferFormat_RGB, stride=-1)

      Copy data from a buffer object to replace the bitmap pixel data.
      Default format is plain ``RGB``, but other formats are now supported as
      well.  The following symbols are used to specify the format of the
      bytes in the buffer:

              =============================  ================================
              wx.BitmapBufferFormat_RGB      A simple sequence of ``RGB`` bytes
              wx.BitmapBufferFormat_RGBA     A simple sequence of ``RGBA`` bytes
              wx.BitmapBufferFormat_ARGB32   A sequence of 32-bit values in native endian order, with alpha in the upper 8 bits, followed by red, green, and blue.
              wx.BitmapBufferFormat_RGB32    Same as above but the alpha byte is ignored.
              =============================  ================================  





   .. method:: CopyFromIcon(self, icon)

      Creates the bitmap from an icon.                  


      :param `icon`: 
      :type `icon`: wx.Icon




      :rtype: `bool`








   .. method:: CopyToBuffer(self, data, format=BitmapBufferFormat_RGB, stride=-1)

      Copy pixel data to a buffer object.  See :meth:`CopyFromBuffer` for buffer
      format details.  





   .. method:: Create(self, *args, **kw)



      |overload| Overloaded Implementations:

      :html:`<hr class="overloadsep" /><br />`

      
      **Create** `(self, width, height, depth=BITMAP_SCREEN_DEPTH)`
      
      Creates a fresh bitmap.                  
      
      If the final argument is omitted, the display depth of the screen is used. 
      
      
      
      
      :param `width`: The width of the bitmap in pixels, must be strictly positive.   
      :type `width`: int
      :param `height`: The height of the bitmap in pixels, must be strictly positive.   
      :type `height`: int
      :param `depth`: The number of bits used to represent each bitmap pixel.  
      :type `depth`: int
      
      
      
      
      
      
      
      
      
      
      :rtype: `bool`
      
      
      
                        
      
      
      
      :returns: 
      
         ``True`` if the creation was successful.   
      
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **Create** `(self, sz, depth=BITMAP_SCREEN_DEPTH)`
      
      This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.                  
      
      
      :param `sz`: 
      :type `sz`: wx.Size
      :param `depth`: 
      :type `depth`: int
      
      
      
      
      :rtype: `bool`
      
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **Create** `(self, width, height, dc)`
      
      Create a bitmap compatible with the given DC, inheriting its magnification factor.                  
      
      
      
      
      :param `width`: The width of the bitmap in pixels, must be strictly positive.   
      :type `width`: int
      :param `height`: The height of the bitmap in pixels, must be strictly positive.   
      :type `height`: int
      :param `dc`: DC from which the scaling factor is inherited  
      :type `dc`: wx.DC
      
      
      
      
      
      
      
      
      
      
      :rtype: `bool`
      
      
      
                        
      
      
      
      :returns: 
      
         ``True`` if the creation was successful.  
      
      
      
      
      
      
      
      .. versionadded:: 4.1/wxWidgets-3.1.0  
           
      
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`






   .. method:: CreateScaled(self, width, height, depth, logicalScale)

      Create a bitmap with a scale factor.                  

      This is an older synonym for :meth:`CreateWithDIPSize` , use the new function in the new code. 




      :param `width`: The width of the bitmap in pixels, must be strictly positive.   
      :type `width`: int
      :param `height`: The height of the bitmap in pixels, must be strictly positive.   
      :type `height`: int
      :param `depth`: The number of bits used to represent each bitmap pixel.   
      :type `depth`: int
      :param `logicalScale`: Scale factor used by the bitmap, see :meth:`SetScaleFactor` .  
      :type `logicalScale`: float












      :rtype: `bool`



                  



      :returns: 

         ``True`` if the creation was successful.  







      .. versionadded:: 4.1/wxWidgets-3.1.0  
     








   .. method:: CreateWithDIPSize(self, *args, **kw)



      |overload| Overloaded Implementations:

      :html:`<hr class="overloadsep" /><br />`

      
      **CreateWithDIPSize** `(self, size, scale, depth=BITMAP_SCREEN_DEPTH)`
      
      Create a bitmap specifying its size in DPI-independent pixels and the scale factor to use.                  
      
      The physical size of the bitmap is obtained by multiplying the given `size`  by `scale`  and rounding it to the closest integer. 
      
      After using this function the following postconditions are ``True``: 
      
      
      
      - :meth:`GetSize`   returns `size`  multiplied by `scale`   
      - :meth:`GetDIPSize`   returns `size`   
      - :meth:`GetScaleFactor`   returns `scale`   
      
      
      
      
      
      
      
      :param `size`: The size of the bitmap in DPI-independent pixels. Both width and height must be strictly positive.   
      :type `size`: wx.Size
      :param `scale`: Scale factor used by the bitmap, see :meth:`SetScaleFactor` .   
      :type `scale`: float
      :param `depth`: The number of bits used to represent each bitmap pixel.  
      :type `depth`: int
      
      
      
      
      
      
      
      
      
      
      :rtype: `bool`
      
      
      
                        
      
      
      
      :returns: 
      
         ``True`` if the creation was successful.  
      
      
      
      
      
      
      
      .. versionadded:: 4.1/wxWidgets-3.1.6  
           
      
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **CreateWithDIPSize** `(self, width, height, scale, depth=BITMAP_SCREEN_DEPTH)`
      
      
      
      This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.                  
      
      
      :param `width`: 
      :type `width`: int
      :param `height`: 
      :type `height`: int
      :param `scale`: 
      :type `scale`: float
      :param `depth`: 
      :type `depth`: int
      
      
      
      
      :rtype: `bool`
      
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`






   .. staticmethod:: FromBuffer(width, height, data)

      Creates a :class:`wx.Bitmap` from in-memory data.  The data parameter
      must be a Python object that implements the buffer interface, such
      as a string, bytearray, etc.  The data object is expected to contain
      a series of ``RGB`` bytes and be at least ``(width  height  3)`` bytes long.

      Unlike :func:`wx.ImageFromBuffer` the bitmap created with this function
      does not share the memory block with the buffer object.  This is
      because the native pixel buffer format varies on different
      platforms, and so instead an efficient as possible copy of the
      data is made from the buffer object to the bitmap's native pixel
      buffer. 

      :rtype: :ref:`wx.Bitmap`








   .. staticmethod:: FromBufferAndAlpha(width, height, data, alpha)

      Creates a :class:`wx.Bitmap` from in-memory data.  The data and alpha
      parameters must be a Python object that implements the buffer
      interface, such as a string, bytearray, etc.  The data object
      is expected to contain a series of ``RGB`` bytes and be at least
      ``(width  height  3)`` bytes long, while the alpha object is expected
      to be ``(width  height)`` bytes long and represents the image's alpha
      channel.  On Windows and Mac the ``RGB`` values will be
      'premultiplied' by the alpha values.  (The other platforms do
      the multiplication themselves.)

      Unlike :func:`wx.ImageFromBuffer` the bitmap created with this function
      does not share the memory block with the buffer object.  This is
      because the native pixel buffer format varies on different
      platforms, and so instead an efficient as possible copy of the
      data is made from the buffer object to the bitmap's native pixel
      buffer. 

      :rtype: :ref:`wx.Bitmap`








   .. staticmethod:: FromBufferRGBA(width, height, data)

      Creates a :class:`wx.Bitmap` from in-memory data.  The data parameter
      must be a Python object that implements the buffer interface, such
      as a string, bytearray, etc.  The data object is expected to contain
      a series of ``RGBA`` bytes and be at least ``(width  height  4)`` bytes long.
      On Windows and Mac the ``RGB`` values will be 'premultiplied' by the
      alpha values.  (The other platforms do the multiplication themselves.)

      Unlike :func:`wx.ImageFromBuffer` the bitmap created with this function
      does not share the memory block with the buffer object.  This is
      because the native pixel buffer format varies on different
      platforms, and so instead an efficient as possible copy of the
      data is made from the buffer object to the bitmap's native pixel
      buffer. 

      :rtype: :ref:`wx.Bitmap`








   .. staticmethod:: FromPNGData(data)

      Like :meth:`NewFromPNGData`, but with a simpler API accepting a Python
      buffer-compatible object. 

      :rtype: :ref:`wx.Bitmap`








   .. staticmethod:: FromRGBA(width, height, red=0, green=0, blue=0, alpha=0)

      Creates a new empty 32-bit :class:`wx.Bitmap` where every pixel has been
      initialized with the given ``RGBA`` values. 

      :rtype: :ref:`wx.Bitmap`








   .. method:: GetDIPSize(self)

      Returns the size of bitmap in DPI-independent units.                  

      This assumes that the bitmap was created using the value of scale factor corresponding to the current ``DPI`` (see :meth:`CreateWithDIPSize`   and :meth:`SetScaleFactor` ) and returns its physical size divided by this scale factor. 

      Unlike :meth:`GetLogicalSize` , this function returns the same value under all platforms and so its result should `not`  be used as window or device context coordinates. 

                

      :rtype: :ref:`wx.Size`







      .. versionadded:: 4.1/wxWidgets-3.1.6  
     








   .. method:: GetDepth(self)

      Gets the colour depth of the bitmap.                  

      A value of 1 indicates a monochrome bitmap.                  

      :rtype: `int`








   .. method:: GetHandle(self)

      MSW-only method to fetch the windows handle for the bitmap. 

      :rtype: `long`








   .. method:: GetHeight(self)

      Returns the height of the bitmap in physical pixels.                  

                

      :rtype: `int`







      .. seealso:: :meth:`GetWidth` , :meth:`GetSize` , :meth:`GetLogicalHeight`     








   .. method:: GetLogicalHeight(self)

      Returns the height of the bitmap in logical pixels.                  

      See :meth:`GetLogicalSize`   for more information. 

                

      :rtype: `float`







      .. versionadded:: 4.1/wxWidgets-3.1.6  
     







      .. seealso:: :meth:`GetLogicalWidth` , :meth:`GetWidth`   








   .. method:: GetLogicalSize(self)

      Returns the size of the bitmap in logical pixels.                  

      For the platforms using DPI-independent pixels, i.e. those where  ``HAS_DPI_INDEPENDENT_PIXELS``   is defined, such as wxOSX or wxGTK 3, this function returns the physical size of the bitmap, as returned by  :meth:`GetSize` , divided by its scale factor, as returned by :meth:`GetScaleFactor` , while for the other platforms, it simply returns the same thing as :meth:`GetSize` . 

      This ensures that the result of this function is always expressed in the pixel coordinates appropriate for the current platform, i.e. its return value is always in logical pixels, used for window and :ref:`wx.DC`  coordinates, whether these pixels are the same as physical pixels, which are returned by :meth:`GetSize` , or not. 

                

      :rtype: :ref:`wx.Size`







      .. versionadded:: 2.9.5 
     







      .. seealso:: :meth:`GetLogicalWidth` , :meth:`GetLogicalHeight` , :meth:`GetSize`   








   .. method:: GetLogicalWidth(self)

      Returns the width of the bitmap in logical pixels.                  

      See :meth:`GetLogicalSize`   for more information. 

                

      :rtype: `float`







      .. versionadded:: 4.1/wxWidgets-3.1.6  
     







      .. seealso:: :meth:`GetLogicalHeight` , :meth:`GetWidth`   








   .. method:: GetMask(self)

      Gets the associated mask (if any) which may have been loaded from a file or set for the bitmap.                  

                

      :rtype: :ref:`wx.Mask`







      .. seealso:: :meth:`SetMask` , :ref:`wx.Mask`    








   .. method:: GetPalette(self)

      Gets the associated palette (if any) which may have been loaded from a file or set for the bitmap.                  

                

      :rtype: :ref:`wx.Palette`







      .. seealso:: :ref:`wx.Palette`    








   .. method:: GetScaleFactor(self)

      Returns the scale factor of this bitmap.                  

      Scale factor is 1 by default, but can be greater to indicate that the size of bitmap in logical, DPI-independent pixels is smaller than its actual size in physical pixels. Bitmaps with scale factor greater than 1 must be used in high ``DPI`` to appear sharp on the screen. 

      Note that the scale factor is only used in the ports where logical pixels are not the same as physical ones, such as wxOSX or ``GTK3``, and this function always returns 1 under the other platforms. 

                

      :rtype: `float`







      .. versionadded:: 2.9.5 
     







      .. seealso:: :meth:`SetScaleFactor` , :meth:`GetLogicalWidth` , :meth:`GetLogicalHeight` , :meth:`GetLogicalSize`   








   .. method:: GetScaledHeight(self)

      Returns the height of the bitmap in logical pixels.                  

      This is an older synonym for :meth:`GetLogicalHeight` , use the new function in the new code. 

                

      :rtype: `float`







      .. versionadded:: 2.9.5 
     








   .. method:: GetScaledSize(self)

      Returns the size of the bitmap in logical pixels.                  

      This is an older synonym for :meth:`GetLogicalSize` , use the new function in the new code. 

                

      :rtype: :ref:`wx.Size`







      .. versionadded:: 2.9.5 
     








   .. method:: GetScaledWidth(self)

      Returns the width of the bitmap in logical pixels.                  

      This is an older synonym for :meth:`GetLogicalWidth` , use the new function in the new code. 

                

      :rtype: `float`







      .. versionadded:: 2.9.5 
     








   .. method:: GetSize(self)

      Returns the size of the bitmap in physical pixels.                  

      The return value of this function doesn't depend on the scale factor, it is always the physical size of the bitmap, i.e. corresponding to the actual number of pixels in it. 

                

      :rtype: :ref:`wx.Size`







      .. versionadded:: 2.9.0 
    







      .. seealso:: :meth:`GetHeight` , :meth:`GetWidth` , :meth:`GetLogicalSize`     








   .. method:: GetSubBitmap(self, rect)

      Returns a sub bitmap of the current one as long as the rect belongs entirely to the bitmap.                  

      This function preserves bit depth and mask information.                  


      :param `rect`: 
      :type `rect`: wx.Rect




      :rtype: :ref:`wx.Bitmap`








   .. method:: GetWidth(self)

      Returns the width of the bitmap in physical pixels.                  

                

      :rtype: `int`







      .. seealso:: :meth:`GetHeight` , :meth:`GetSize` , :meth:`GetLogicalWidth`     








   .. method:: HasAlpha(self)

      Returns ``True`` if the bitmap has an alpha channel.                  

      Note that the fact that a bitmap has an alpha channel doesn't necessarily mean that it has any transparency, as all of its pixels could be using ``wx.ALPHA_OPAQUE`` value. To actually examine the alpha values, the bitmap can be converted to :ref:`wx.Image`.                  

      :rtype: `bool`








   .. method:: IsOk(self)

      Returns ``True`` if bitmap data is present.                  

      :rtype: `bool`








   .. method:: LoadFile(self, name, type=BITMAP_TYPE_ANY)

      Loads a bitmap from a file or resource.                  




      :param `name`: Either a filename or a Windows resource name. The meaning of name is determined by the  `type`  parameter.   
      :type `name`: string
      :param `type`: One of the :ref:`wx.BitmapType`  values; see the note in the class detailed description. Note that the ``BITMAP_DEFAULT_TYPE`` constant has different value under different wxWidgets ports. See the bitmap.h header for the value it takes for a specific port.  
      :type `type`: wx.BitmapType








      :rtype: `bool`



                  



      :returns: 

         ``True`` if the operation succeeded, ``False`` otherwise.  







      .. note:: 

         A palette may be associated with the bitmap if one exists (especially for colour Windows bitmaps), and if the code supports it. You can check if one has been created by using the :meth:`GetPalette`   member.  







      .. seealso:: :meth:`SaveFile`     








   .. staticmethod:: NewFromPNGData(data, size)

      Loads a bitmap from the memory containing image data in ``PNG`` format.                  

      This helper function provides the simplest way to create a wx.Bitmap from
      in-memory ``PNG`` image data. 


      :param `data`: 
      :param `size`: 
      :type `size`: int




      :rtype: :ref:`wx.Bitmap`








   .. staticmethod:: Rescale(bmp, sizeNeeded)

      Rescale the given bitmap to the requested size.                  

      This function is just a convenient wrapper for :meth:`wx.Image.Rescale`   used to resize the given `bmp`  to the requested size. If you need more control over resizing, e.g. to specify the quality option different from ``IMAGE_QUALITY_NEAREST``  used by this function, please use the :ref:`wx.Image`  function directly instead. 

      Both the bitmap itself and size must be valid. 

                


      :param `bmp`: 
      :type `bmp`: wx.Bitmap
      :param `sizeNeeded`: 
      :type `sizeNeeded`: wx.Size






      .. versionadded:: 4.1/wxWidgets-3.1.6  
     








   .. method:: ResetAlpha(self)

      Remove alpha channel from the bitmap.                  

      This is the same as calling :meth:`UseAlpha`   with ``False`` argument.                   





   .. method:: SaveFile(self, name, type, palette=None)

      Saves a bitmap in the named file.                  




      :param `name`: A filename. The meaning of name is determined by the type parameter.   
      :type `name`: string
      :param `type`: One of the :ref:`wx.BitmapType`  values; see the note in the class detailed description.   
      :type `type`: wx.BitmapType
      :param `palette`: An optional palette used for saving the bitmap.  
      :type `palette`: wx.Palette










      :rtype: `bool`



                  



      :returns: 

         ``True`` if the operation succeeded, ``False`` otherwise.  







      .. note:: 

         Depending on how wxWidgets has been configured, not all formats may be available.  







      .. seealso:: :meth:`LoadFile`     








   .. method:: SetDepth(self, depth)





      Sets the depth member (does not affect the bitmap data). 




      :param `depth`: Bitmap depth.   
      :type `depth`: int




                  



      .. wxdeprecated:: 
         This function is deprecated since version 3.1.2, dimensions and depth can only be set at construction time.   








   .. method:: SetHandle(self, handle)

      MSW-only method to set the windows handle for the bitmap.  





   .. method:: SetHeight(self, height)





      Sets the height member (does not affect the bitmap data). 




      :param `height`: Bitmap height in pixels.   
      :type `height`: int




                  



      .. wxdeprecated:: 
         This function is deprecated since version 3.1.2, dimensions and depth can only be set at construction time.   








   .. method:: SetMask(self, mask)

      Sets the mask for this bitmap.                  

                


      :param `mask`: 
      :type `mask`: wx.Mask






      .. note:: 

         The bitmap object owns the mask once this has been called.  







      .. note:: 

         A mask can be set also for bitmap with an alpha channel but doing so under wxMSW is not recommended because performance of drawing such bitmap is not very good.  







      .. seealso:: :meth:`GetMask` , :ref:`wx.Mask`    








   .. method:: SetMaskColour(self, colour)

      Create a mask for this bitmap based on the pixels with the given colour.  





   .. method:: SetPalette(self, palette)

      Sets the associated palette.                  

      (Not implemented under GTK+). 




      :param `palette`: The palette to set.  
      :type `palette`: wx.Palette




                  



      .. seealso:: :ref:`wx.Palette`    








   .. method:: SetScaleFactor(self, scale)

      Sets the bitmap scale factor.                  

      This doesn't change the bitmap actual size or its contents, but changes its scale factor, so that it appears in a smaller size when it is drawn on screen: e.g. setting `scale`  to 2 means that the bitmap will be twice smaller (in each direction) when drawn on screen in the ports in which logical and physical pixels differ (i.e. wxOSX and ``GTK3``, but not wxMSW). 

      When creating a new bitmap, :meth:`CreateWithDIPSize`   can be used to specify the correct scale factor from the beginning. 

                


      :param `scale`: 
      :type `scale`: float






      .. versionadded:: 4.1/wxWidgets-3.1.6  
     








   .. method:: SetSize(self, size)

      Set the bitmap size (does not alter the existing native bitmap data or image size).  





   .. method:: SetWidth(self, width)





      Sets the width member (does not affect the bitmap data). 




      :param `width`: Bitmap width in pixels.   
      :type `width`: int




                  



      .. wxdeprecated:: 
         This function is deprecated since version 3.1.2, dimensions and depth can only be set at construction time.   








   .. method:: UseAlpha(self, use=True)

      Enable or disable use of alpha channel in this bitmap.                  

      This function is only useful for 32bpp bitmaps and changes their format to use, or not use, the fourth byte of the pixel data for the alpha channel. 

      It currently is only implemented in wxMSW and wxOSX and simply always returns ``False`` under the other platforms. 

                


      :param `use`: 
      :type `use`: bool






      :returns: 

         ``True`` if the operation succeeded, ``False`` otherwise, e.g. when trying to enable alpha channel support for a non-32bpp bitmap or if this operation is simply not supported by the current platform.  







      .. seealso:: :meth:`HasAlpha` , :meth:`ResetAlpha`     








   .. method:: __bool__(self)



      :rtype: `int`








   .. method:: __nonzero__(self)



      :rtype: `int`








   .. attribute:: DIPSize

      See :meth:`~wx.Bitmap.GetDIPSize`


   .. attribute:: Depth

      See :meth:`~wx.Bitmap.GetDepth` and :meth:`~wx.Bitmap.SetDepth`


   .. attribute:: Handle

      See :meth:`~wx.Bitmap.GetHandle` and :meth:`~wx.Bitmap.SetHandle`


   .. attribute:: Height

      See :meth:`~wx.Bitmap.GetHeight` and :meth:`~wx.Bitmap.SetHeight`


   .. attribute:: LogicalHeight

      See :meth:`~wx.Bitmap.GetLogicalHeight`


   .. attribute:: LogicalSize

      See :meth:`~wx.Bitmap.GetLogicalSize`


   .. attribute:: LogicalWidth

      See :meth:`~wx.Bitmap.GetLogicalWidth`


   .. attribute:: Mask

      See :meth:`~wx.Bitmap.GetMask` and :meth:`~wx.Bitmap.SetMask`


   .. attribute:: Palette

      See :meth:`~wx.Bitmap.GetPalette` and :meth:`~wx.Bitmap.SetPalette`


   .. attribute:: ScaleFactor

      See :meth:`~wx.Bitmap.GetScaleFactor` and :meth:`~wx.Bitmap.SetScaleFactor`


   .. attribute:: ScaledHeight

      See :meth:`~wx.Bitmap.GetScaledHeight`


   .. attribute:: ScaledSize

      See :meth:`~wx.Bitmap.GetScaledSize`


   .. attribute:: ScaledWidth

      See :meth:`~wx.Bitmap.GetScaledWidth`


   .. attribute:: Size

      See :meth:`~wx.Bitmap.GetSize` and :meth:`~wx.Bitmap.SetSize`


   .. attribute:: Width

      See :meth:`~wx.Bitmap.GetWidth` and :meth:`~wx.Bitmap.SetWidth`

