# wxBitmap Class Reference
[Graphics Device Interface (GDI)]

`#include </home/work/projects/wx/2.9/wx/interface/wx/bitmap.h>`

Inheritance diagram for wxBitmap:
[legend]

## Detailed Description

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 wxMemoryDC you need to use the wxPixelData class (either wxNativePixelData for RGB bitmaps or wxAlphaPixelData for bitmaps with an additionaly alpha channel).

Note that many wxBitmap functions take a type parameter, which is a value of the wxBitmapType 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 XPM files;
- wxMac supports PICT resources;
- wxX11 supports XPM files, XPM data, XBM data;

In addition, wxBitmap can load and save all formats that wxImage can; see wxImage for more info. Of course, you must have loaded the wxImage handlers (see wxInitAllImageHandlers() and wxImage::AddHandler). Note that all available wxBitmapHandlers for a given wxWidgets port are automatically loaded at startup so you won't need to use wxBitmap::AddHandler.

##

Library: wxCore
Category: Graphics Device Interface (GDI)

Predefined objects/pointers: wxNullBitmap

See also:
  Bitmaps and Icons, Supported Bitmap File Formats, wxDC::Blit, wxIcon, wxCursor, wxMemoryDC, wxImage, wxPixelData

## Public Member Functions

| wxBitmap ()
| Default constructor.
| wxBitmap (const wxBitmap &bitmap)
| Copy constructor, uses reference counting.
| wxBitmap (const char bits[], int width, int height, int depth=1)
| Creates a bitmap from the given array bits.
| wxBitmap (int width, int height, int depth=wxBITMAP_SCREEN_DEPTH)
| Creates a new bitmap.
| wxBitmap (const wxSize &sz, int depth=wxBITMAP_SCREEN_DEPTH)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| wxBitmap (const char *const *bits)
| Creates a bitmap from XPM data.
| wxBitmap (const wxString &name, wxBitmapType type=wxBITMAP_DEFAULT_TYPE)
| Loads a bitmap from a file or resource.
| wxBitmap (const wxImage &img, int depth=wxBITMAP_SCREEN_DEPTH)
| Creates this bitmap object from the given image.
virtual | ~wxBitmap ()
| Destructor.
virtual wxImage | ConvertToImage () const
| Creates an image from a platform-dependent bitmap.
virtual bool | CopyFromIcon (const wxIcon &icon)
| Creates the bitmap from an icon.
virtual bool | Create (int width, int height, int depth=wxBITMAP_SCREEN_DEPTH)
| Creates a fresh bitmap.
virtual bool | Create (const wxSize &sz, int depth=wxBITMAP_SCREEN_DEPTH)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
virtual int | GetDepth () const
| Gets the colour depth of the bitmap.
virtual int | GetHeight () const
| Gets the height of the bitmap in pixels.
virtual wxMask * | GetMask () const
| Gets the associated mask (if any) which may have been loaded from a file or set for the bitmap.
virtual wxPalette * | GetPalette () const
| Gets the associated palette (if any) which may have been loaded from a file or set for the bitmap.
virtual wxBitmap | GetSubBitmap (const wxRect &rect) const
| Returns a sub bitmap of the current one as long as the rect belongs entirely to the bitmap.
wxSize | GetSize () const
| Returns the size of the bitmap in pixels.
wxBitmap | ConvertToDisabled (unsigned char brightness=255) const
| Returns disabled (dimmed) version of the bitmap.
virtual int | GetWidth () const
| Gets the width of the bitmap in pixels.
virtual bool | IsOk () const
| Returns true if bitmap data is present.
virtual bool | LoadFile (const wxString &name, wxBitmapType type=wxBITMAP_DEFAULT_TYPE)
| Loads a bitmap from a file or resource.
virtual bool | SaveFile (const wxString &name, wxBitmapType type, const wxPalette *palette=NULL) const
| Saves a bitmap in the named file.
virtual void | SetDepth (int depth)
| Sets the depth member (does not affect the bitmap data).
virtual void | SetHeight (int height)
| Sets the height member (does not affect the bitmap data).
virtual void | SetMask (wxMask *mask)
| Sets the mask for this bitmap.
virtual void | SetPalette (const wxPalette &palette)
| Sets the associated palette.
virtual void | SetWidth (int width)
| Sets the width member (does not affect the bitmap data).

## Static Public Member Functions

static void | AddHandler (wxBitmapHandler *handler)
| Adds a handler to the end of the static list of format handlers.
static void | CleanUpHandlers ()
| Deletes all bitmap handlers.
static wxBitmapHandler * | FindHandler (const wxString &name)
| Finds the handler with the given name.
static wxBitmapHandler * | FindHandler (const wxString &extension, wxBitmapType bitmapType)
| Finds the handler associated with the given extension and type.
static wxBitmapHandler * | FindHandler (wxBitmapType bitmapType)
| Finds the handler associated with the given bitmap type.
static wxList & | GetHandlers ()
| Returns the static list of bitmap format handlers.
static void | InitStandardHandlers ()
| Adds the standard bitmap format handlers, which, depending on wxWidgets configuration, can be handlers for Windows bitmap, Windows bitmap resource, and XPM.
static void | InsertHandler (wxBitmapHandler *handler)
| Adds a handler at the start of the static list of format handlers.
static bool | RemoveHandler (const wxString &name)
| Finds the handler with the given name, and removes it.

List of all members.

## Constructor & Destructor Documentation

wxBitmap::wxBitmap | ( |  | ) |

Default constructor.

Constructs a bitmap object with no data; an assignment or another member function such as Create() or LoadFile() must be called subsequently.

wxBitmap::wxBitmap | ( | const wxBitmap & | bitmap | ) |

Copy constructor, uses reference counting.

To make a real copy, you can use:

            wxBitmap newBitmap = oldBitmap.GetSubBitmap(
                                 wxRect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));

wxBitmap::wxBitmap | ( | const char | bits[],
|  | int | width,
|  | int | height,
|  | int | 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 wxImage should be used for creating colour bitmaps from static data.

Parameters:

  | bits | Specifies an array of pixel values.
  | width | Specifies the width of the bitmap.
  | height | Specifies the height of the bitmap.
  | depth | Specifies the depth of the bitmap. If this is omitted, then a value of 1 (monochrome bitmap) is used.

wxPerl Note: In wxPerl use Wx::Bitmap->newFromBits(bits, width, height, depth).

wxBitmap::wxBitmap | ( | int | width,
|  | int | height,
|  | int | depth = `wxBITMAP_SCREEN_DEPTH` |
| ) |  |  |

Creates a new bitmap.

A depth of wxBITMAP_SCREEN_DEPTH indicates the depth of the current screen or visual.

Some platforms only support 1 for monochrome and wxBITMAP_SCREEN_DEPTH for the current colour setting.

A depth of 32 including an alpha channel is supported under MSW, Mac and GTK+.

wxBitmap::wxBitmap | ( | const wxSize & | sz,
|  | int | depth = `wxBITMAP_SCREEN_DEPTH` |
| ) |  |  |

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

wxBitmap::wxBitmap | ( | const char *const * | bits | ) |

Creates a bitmap from XPM data.

wxPerl Note: In wxPerl use Wx::Bitmap->newFromXPM(data).

wxBitmap::wxBitmap | ( | const wxString & | name,
|  | wxBitmapType | type = `wxBITMAP_DEFAULT_TYPE` |
| ) |  |  |

Loads a bitmap from a file or resource.

Parameters:

  | 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 | May be one of the wxBitmapType values and indicates which type of bitmap should be loaded. See the note in the class detailed description. Note that the wxBITMAP_DEFAULT_TYPE constant has different value under different wxWidgets ports. See the bitmap.h header for the value it takes for a specific port.

See also:
  LoadFile()

wxBitmap::wxBitmap | ( | const wxImage & | img,
|  | int | depth = `wxBITMAP_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 wxBITMAP_SCREEN_DEPTH) which entails that a colour reduction may take place.

When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube created on program start-up to look up colors. This ensures a very fast conversion, but the image quality won't be perfect (and could be better for photo images using more sophisticated dithering algorithms).

On Windows, if there is a palette present (set with SetPalette), it will be used when creating the wxBitmap (most useful in 8-bit display mode). On other platforms, the palette is currently ignored.

Parameters:

  | img | Platform-independent wxImage object.
  | depth | Specifies the depth of the bitmap. If this is omitted, the display depth of the screen is used.

virtual wxBitmap::~wxBitmap | ( |  | ) | `[virtual]`

Destructor.

See Object Destruction for more info.

If the application omits to delete the bitmap explicitly, the bitmap will be destroyed automatically by wxWidgets when the application exits.

Warning:
  Do not delete a bitmap that is selected into a memory device context.

## Member Function Documentation

static void wxBitmap::AddHandler | ( | wxBitmapHandler * | handler | ) | `[static]`

Adds a handler to the end of the static list of format handlers.

Parameters:

  | handler | A new bitmap format handler object. There is usually only one instance of a given handler class in an application session.

Note that unlike wxImage::AddHandler, there's no documented list of the wxBitmapHandlers available in wxWidgets. This is because they are platform-specific and most important, they are all automatically loaded at startup.

If you want to be sure that wxBitmap can load a certain type of image, you'd better use wxImage::AddHandler.

See also:
  wxBitmapHandler

static void wxBitmap::CleanUpHandlers | ( |  | ) | `[static]`

Deletes all bitmap handlers.

This function is called by wxWidgets on exit.

wxBitmap wxBitmap::ConvertToDisabled | ( | unsigned char | brightness = `255` | ) | const

Returns disabled (dimmed) version of the bitmap.

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

Since:
  2.9.0

Reimplemented in wxIcon.

virtual wxImage wxBitmap::ConvertToImage | ( |  | ) | const`[virtual]`

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.

virtual bool wxBitmap::CopyFromIcon | ( | const wxIcon & | icon | ) | `[virtual]`

Creates the bitmap from an icon.

virtual bool wxBitmap::Create | ( | int | width,
|  | int | height,
|  | int | depth = `wxBITMAP_SCREEN_DEPTH` |
| ) |  |  | `[virtual]`

Creates a fresh bitmap.

If the final argument is omitted, the display depth of the screen is used.

Returns:
  true if the creation was successful.

virtual bool wxBitmap::Create | ( | const wxSize & | sz,
|  | int | depth = `wxBITMAP_SCREEN_DEPTH` |
| ) |  |  | `[virtual]`

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

static wxBitmapHandler* wxBitmap::FindHandler | ( | const wxString & | extension,
|  | wxBitmapType | bitmapType |
| ) |  |  | `[static]`

Finds the handler associated with the given extension and type.

Parameters:

  | extension | The file extension, such as "bmp" (without the dot).
  | bitmapType | The bitmap type managed by the handler, see wxBitmapType.

Returns:
  A pointer to the handler if found, NULL otherwise.

static wxBitmapHandler* wxBitmap::FindHandler | ( | wxBitmapType | bitmapType | ) | `[static]`

Finds the handler associated with the given bitmap type.

Parameters:

  | bitmapType | The bitmap type managed by the handler, see wxBitmapType.

Returns:
  A pointer to the handler if found, NULL otherwise.

See also:
  wxBitmapHandler

static wxBitmapHandler* wxBitmap::FindHandler | ( | const wxString & | name | ) | `[static]`

Finds the handler with the given name.

Returns:
  A pointer to the handler if found, NULL otherwise.

virtual int wxBitmap::GetDepth | ( |  | ) | const`[virtual]`

Gets the colour depth of the bitmap.

A value of 1 indicates a monochrome bitmap.

Reimplemented in wxIcon.

static wxList& wxBitmap::GetHandlers | ( |  | ) | `[static]`

Returns the static list of bitmap format handlers.

See also:
  wxBitmapHandler

virtual int wxBitmap::GetHeight | ( |  | ) | const`[virtual]`

Gets the height of the bitmap in pixels.

See also:
  GetWidth(), GetSize()

Reimplemented in wxIcon.

virtual wxMask* wxBitmap::GetMask | ( |  | ) | const`[virtual]`

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

See also:
  SetMask(), wxMask

virtual wxPalette* wxBitmap::GetPalette | ( |  | ) | const`[virtual]`

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

See also:
  wxPalette

wxSize wxBitmap::GetSize | ( |  | ) | const

Returns the size of the bitmap in pixels.

Since:
  2.9.0

See also:
  GetHeight(), GetWidth()

virtual wxBitmap wxBitmap::GetSubBitmap | ( | const wxRect & | rect | ) | const`[virtual]`

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.

virtual int wxBitmap::GetWidth | ( |  | ) | const`[virtual]`

Gets the width of the bitmap in pixels.

See also:
  GetHeight(), GetSize()

Reimplemented in wxIcon.

static void wxBitmap::InitStandardHandlers | ( |  | ) | `[static]`

Adds the standard bitmap format handlers, which, depending on wxWidgets configuration, can be handlers for Windows bitmap, Windows bitmap resource, and XPM.

This function is called by wxWidgets on startup.

See also:
  wxBitmapHandler

static void wxBitmap::InsertHandler | ( | wxBitmapHandler * | handler | ) | `[static]`

Adds a handler at the start of the static list of format handlers.

Parameters:

  | handler | A new bitmap format handler object. There is usually only one instance of a given handler class in an application session.

See also:
  wxBitmapHandler

virtual bool wxBitmap::IsOk | ( |  | ) | const`[virtual]`

Returns true if bitmap data is present.

Reimplemented in wxIcon.

virtual bool wxBitmap::LoadFile | ( | const wxString & | name,
|  | wxBitmapType | type = `wxBITMAP_DEFAULT_TYPE` |
| ) |  |  | `[virtual]`

Loads a bitmap from a file or resource.

Parameters:

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

Returns:
  true if the operation succeeded, false otherwise.

Remarks:
  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()

static bool wxBitmap::RemoveHandler | ( | const wxString & | name | ) | `[static]`

Finds the handler with the given name, and removes it.

The handler is not deleted.

Parameters:

  | name | The handler name.

Returns:
  true if the handler was found and removed, false otherwise.

See also:
  wxBitmapHandler

virtual bool wxBitmap::SaveFile | ( | const wxString & | name,
|  | wxBitmapType | type,
|  | const wxPalette * | palette = `NULL` |
| ) |  |  | const`[virtual]`

Saves a bitmap in the named file.

Parameters:

  | name | A filename. The meaning of name is determined by the type parameter.
  | type | One of the wxBitmapType values; see the note in the class detailed description.
  | palette | An optional palette used for saving the bitmap.

Returns:
  true if the operation succeeded, false otherwise.

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

See also:
  LoadFile()

virtual void wxBitmap::SetDepth | ( | int | depth | ) | `[virtual]`

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

Todo:
  since these functions do not affect the bitmap data, why they exist??

Parameters:

  | depth | Bitmap depth.

Reimplemented in wxIcon.

virtual void wxBitmap::SetHeight | ( | int | height | ) | `[virtual]`

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

Parameters:

  | height | Bitmap height in pixels.

Reimplemented in wxIcon.

virtual void wxBitmap::SetMask | ( | wxMask * | mask | ) | `[virtual]`

Sets the mask for this bitmap.

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

See also:
  GetMask(), wxMask

virtual void wxBitmap::SetPalette | ( | const wxPalette & | palette | ) | `[virtual]`

Sets the associated palette.

(Not implemented under GTK+).

Parameters:

  | palette | The palette to set.

See also:
  wxPalette

virtual void wxBitmap::SetWidth | ( | int | width | ) | `[virtual]`

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

Parameters:

  | width | Bitmap width in pixels.

Reimplemented in wxIcon.

|  | [ top ]