Author image Kevin Ryde
and 1 contributors


Image::Base::Wx::Bitmap -- draw into a Wx::Bitmap


 use Image::Base::Wx::Bitmap;
 my $image = Image::Base::Wx::Bitmap->new
                 (-wxbitmap => $wxbitmap);
 $image->line (0,0, 99,99, '#FF00FF');
 $image->rectangle (10,10, 20,15, 'white');


Image::Base::Wx::Bitmap is a subclass of Image::Base::Wx::DC,



Image::Base::Wx::Bitmap extends Image::Base to draw into a Wx::Bitmap.

Wx::Bitmap is a platform-dependent colour image with a specified bits-per-pixel depth. The supported depths depend on the platform but include at least the screen depth and 1-bit monochrome.

Drawing is done with a wxMemoryDC as per the Image::Base::Wx::DC. This subclass adds file load and save for the Wx::Bitmap.

File Formats

The file formats supported in Wx 2.8 include the following, perhaps depending which supporting libraries it was built with.

    BMP      always available
    GIF      load-only
    TGA      load-only
    IFF      load-only
    ANI      load-only

load() detects the format, but a wxBitmapHandler for the format must have been registered globally. Wx normally has all available handlers pre-loaded and believe WxPerl consequently omits a Wx::InitStandardHandlers().

Colour Names

Colour names are anything recognised by Wx::Colour->new(), as described in "Colour Names" in Image::Base::Wx::DC.


See "FUNCTIONS" in Image::Base for behaviour common to all Image-Base classes.

$image = Image::Base::Wx::Bitmap->new (key=>value,...)

Create and return a new image object. It can read a file,

    $image = Image::Base::Wx::Bitmap->new
               (-file => '/my/file/name.bmp');

Or create a new bitmap with width and height. The default -depth is the bits-per-pixel of the screen, or something else can be given.

    $image = Image::Base::Wx::Bitmap->new
                 (-width  => 200,
                  -height => 100,
                  -depth => 1);   # monochrome

Or a new image can be pointed at an existing Wx::Bitmap,

    my $wxbitmap = Wx::Bitmap->new (200, 100);
    my $image = Image::Base::Wx::Bitmap->new
                 (-wxbitmap => $wxbitmap);

Further parameters are applied per set (see "ATTRIBUTES" below).


-wxbitmap (Wx::Bitmap object)

The target bitmap object.

-dc (Wx::MemoryDC object)

The Wx::DC used to draw into the bitmap. A suitable DC is created for the bitmap automatically, but it can be set explicitly if desired.

-file_format (string, default undef)

The file format to save(). This is one of the wxBITMAP_TYPE_XXX names such as "PNG" or "JPEG".

-width (integer, read-only)
-height (integer, read-only)

The size of the bitmap, per $wxbitmap->GetWidth() and $wxbitmap->GetHeight(). Currently these are read-only. Can a bitmap be resized dynamically?

-depth (integer, read-only)

The number of bits per pixel in the bitmap, per $wxbitmap->GetDepth(). Currently this is read-only. Can a bitmap be reformatted dynamically?


Wx circa 2.8.12 on Gtk prints g_log() warnings on attempting to load an unknown file format, including an empty file or garbage. This is apparently from attempting it as an XPM. Is that a Wx bug?

In the past, load() set -file_format to the format of the file just loaded. Alas Wx circa 3.0.4 seems to load any file format it can, without indicating which it was. Applications using load() will have seen -file_format wrongly set always "BMP". Would like load() to set what it read, but there doesn't seem to be a convenient way (short of reading with Wx::Image and discarding). For now, load() doesn't set -file_format at all.


Wx, Image::Base, Image::Base::Wx::DC, Image::Base::Wx::Image



Copyright 2012, 2019 Kevin Ryde

Image-Base-Wx is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Image-Base-Wx is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Image-Base-Wx. If not, see <>.