wx.Bitmap

Inheritance diagram for wx.Bitmap:



Description

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

Derived From

Class API

Methods

__init__(name, type=wx.BITMAP_TYPE_ANY)

Loads a bitmap from a file.

Alternative constructors supported by wxPython are:

Alternative Constructors Description
wx.EmptyBitmap (width, height, depth=-1) Creates an empty bitmap with the given specifications.
wx.BitmapFromXPMData (listOfStrings) Create a bitmap from a Python list of strings whose contents are XPM data.
wx.BitmapFromBits (bits, width, height, depth=-1) Create a bitmap from an array of bits contained in a string.
wx.BitmapFromImage (image, depth=-1) Convert a wx.Image to a wx.Bitmap.
wx.BitmapFromBuffer (width, height, dataBuffer, alphaBuffer=None) Creates a wx.Bitmap from the data in dataBuffer.
wx.BitmapFromBufferRGBA (width, height, dataBuffer) Creates a wx.Bitmap from the data in dataBuffer.
wx.BitmapFromIcon (icon) Creates a wx.Bitmap from a wx.Icon object.

Parameters:

  • name (string)
  • type (int)

Returns:

wx.Bitmap


ConvertToImage()

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.


Returns:

wx.Image


CopyFromBuffer(data, format=wx.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:

Format Flag Description
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.

Parameters:

  • data (buffer)
  • format (int)
  • stride (int)

CopyFromBufferRGBA(buffer)

Copy data from a RGBA buffer object to replace the bitmap pixel data. This method is now just a compatibility wrapper around CopyFrombuffer.

Parameters:

  • buffer

CopyFromCursor(cursor)

Parameters:


Returns:

bool


CopyFromIcon(icon)

Creates the bitmap from an icon.

Parameters:


Returns:

bool


CopyToBuffer(data, format=wx.BitmapBufferFormat_RGB, stride=-1)

Copy pixel data to a buffer object. See CopyFromBuffer for buffer format.

Parameters:

  • data (buffer)
  • format (int)
  • stride (int)

GetDepth()

Gets the colour depth of the bitmap. A value of 1 indicates a monochrome bitmap.


Returns:

int


GetHandle()
No docstrings available for this method.

GetHeight()

Gets the height of the bitmap in pixels.


Returns:

int


GetMask()

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


Returns:

wx.Mask

See also

SetMask, wx.Mask


GetPalette()

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


Returns:

wx.Palette

See also

wx.Palette


GetSize()

Get the size of the bitmap.


Returns:

wx.Size


GetSubBitmap(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.

Parameters:


Returns:

wx.Bitmap


GetWidth()

Gets the width of the bitmap in pixels.


Returns:

int

See also

GetHeight


HasAlpha()
Returns True if the bitmap has an alpha mask.

IsOk()

Returns True if bitmap data is present.


Returns:

bool


LoadFile(name, type)

Loads a bitmap from a file or resource.

Parameters:

  • name (string): Either a filename or a Windows resource name. The meaning of name is determined by the type parameter.

  • type (int): One of the following values:

    wx.BITMAP_TYPE_BMP

    Load a Windows bitmap file.

    wx.BITMAP_TYPE_BMP_RESOURCE

    Load a Windows bitmap resource from the executable.

    wx.BITMAP_TYPE_PICT_RESOURCE

    Load a PICT image resource from the executable. Mac OS only.

    wx.BITMAP_TYPE_GIF

    Load a GIF bitmap file.

    wx.BITMAP_TYPE_XBM

    Load an X bitmap file.

    wx.BITMAP_TYPE_XPM

    Load an XPM bitmap file.

The validity of these flags depends on the platform and wxWidgets configuration.

In addition, wx.Bitmap can read all formats that wx.Image can (wx.BITMAP_TYPE_JPEG, wx.BITMAP_TYPE_PNG, wx.BITMAP_TYPE_GIF, wx.BITMAP_TYPE_PCX, wx.BITMAP_TYPE_PNM).


Returns:

bool

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 GetPalette member.

See also

SaveFile


SaveFile(name, type, palette=None)

Saves a bitmap in the named file.

Parameters:

  • name (string): A filename. The meaning of name is determined by the type parameter.

  • type (int): One of the following values:

    wx.BITMAP_TYPE_BMP

    Save a Windows bitmap file.

    wx.BITMAP_TYPE_GIF

    Save a GIF bitmap file.

    wx.BITMAP_TYPE_XBM

    Save an X bitmap file.

    wx.BITMAP_TYPE_XPM

    Save an XPM bitmap file.

    In addition, wx.Bitmap can read all formats that wx.Image can (i.e., wx.BITMAP_TYPE_JPEG, wx.BITMAP_TYPE_PNG, wx.BITMAP_TYPE_GIF, wx.BITMAP_TYPE_PCX, wx.BITMAP_TYPE_PNM).

  • palette (wx.Palette): An optional palette used for saving the bitmap.


Returns:

bool

Note

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

See also

LoadFile


SetDepth(depth)

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

Parameters:

  • depth (int): Bitmap depth.

SetHandle(handle)

Parameters:

  • handle (long)

SetHeight(height)

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

Parameters:

  • height (int): Bitmap height in pixels.

SetMask(mask)

Sets the mask for this bitmap.

Parameters:

Note

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

See also

GetMask , wx.Mask


SetMaskColour(colour)

Create a mask based on a specified colour in the Bitmap.

Parameters:


SetPalette(palette)

Sets the associated palette. (Not implemented under GTK+).

Parameters:

See also

wx.Palette


SetSize(size)

Set the bitmap size (does not affect the existing bitmap data).

Parameters:


SetWidth(width)

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

Parameters:

  • width (int): Bitmap width in pixels.

UseAlpha()
No docstrings available for this method.

Properties

Depth
See GetDepth and SetDepth
Height
See GetHeight and SetHeight
Mask
See GetMask and SetMask
Palette
See GetPalette
Size
See GetSize and SetSize
SubBitmap
See GetSubBitmap
Width
See GetWidth and SetWidth