Image Classes in wxWidgets

team bbl


wxWidgets supports four kinds of bitmap images: wxBitmap, wxIcon, wxCursor, and wxImage.

wxBitmap represents a platform-dependent bitmap, with an optional wxMask to support drawing with transparency. On Windows, wxBitmap is implemented using device-independent bitmaps (DIBs). On GTK+ and X11, each wxBitmap contains the pixmap object of GDK and X11, respectively. On Mac, a PICT is used. A wxBitmap can be converted to and from a wxImage.

wxIcon represents the platform's concept of an icon, a small image with transparency that can be used for giving frames and dialogs a recognizable visual cue, among other things. On GTK+, X11, and Mac, an icon is simply a bitmap that always has a wxMask. On Windows, an icon is represented by an HICON object.

wxCursor represents the mouse pointer image; this is a GdkCursor on GTK+, a Cursor on X11, an HCURSOR in Windows, and a Cursor on Mac. It has the notion of a hotspot (the pixel in the cursor image that is considered to be the exact mouse pointer location) and a mask.

wxImage is the only class of the four with a platform-independent implementation, supporting 24-bit images with an optional alpha channel. A wxImage can be created from data or by using wxBitmap::ConvertToImage. A wxImage can be loaded from a file in a variety of formats, and it is extensible to new formats via image format handlers. Functions are available to set and get image bits, so it can be used for basic image manipulation. Unlike a wxBitmap, a wxImage cannot be drawn directly to a wxDC. Instead, a wxBitmap object must be created from the wxImage. This bitmap can then be drawn in a device context by using wxDC:: DrawBitmap. wxImage supports a mask color indicating transparent areas, and it also supports alpha channel data to allow for more sophisticated transparency effects.

You can convert between these bitmap objects, though there are platform dependencies on some conversion operations.

Note that all image classes are reference-counted, so assignment and copying are very cheap operations because the image data itself is not copied. However, you need to be aware that if you change an image, other image objects that refer to the same image data will also be changed.

All image classes use standard wxBitmapType identifiers for loading and saving bitmap data, as described in Table 10-1.

Table 10-1. Bitmap Types

wxBITMAP_TYPE_BMP

A Windows bitmap file (BMP).

wxBITMAP_TYPE_BMP_RESOURCE

A Windows bitmap to be loaded from the resource part of the executable.

wxBITMAP_TYPE_ICO

A Windows icon file (ICO).

wxBITMAP_TYPE_ICO_RESOURCE

A Windows icon to be loaded from the resource part of the executable.

wxBITMAP_TYPE_CUR

A Windows cursor (CUR).

wxBITMAP_TYPE_CUR_RESOURCE

A Windows cursor to be loaded from the resource part of the executable.

wxBITMAP_TYPE_XBM

An XBM monochrome bitmap file, used on Unix.

wxBITMAP_TYPE_XBM_DATA

An XBM monochrome bitmap, to be constructed from C++ data.

wxBITMAP_TYPE_XPM

An XPM color bitmap file, a good cross-platform format for small images that can be compiled into the application.

wxBITMAP_TYPE_XPM_DATA

An XPM color bitmap, to be constructed from C++ data.

wxBITMAP_TYPE_TIF

A TIFF bitmap file, popular for large images.

wxBITMAP_TYPE_GIF

A GIF bitmap file, with a maximum 256 colors and optional transparency information.

wxBITMAP_TYPE_PNG

A PNG bitmap file, a popular file format with optional transparency and alpha channel, and free of patent problems.

wxBITMAP_TYPE_JPEG

A JPEG bitmap file, a popular compressed format for large images, but it uses lossy compression, so it's not suitable for multiple saving/loading cycles.

wxBITMAP_TYPE_PCX

PCX bitmap file.

wxBITMAP_TYPE_PICT

Mac PICT bitmap file.

wxBITMAP_TYPE_PICT_RESOURCE

Mac PICT bitmap file to be loaded from the resource part of the executable.

wxBITMAP_TYPE_ICON_RESOURCE

On Mac OS X only, loads a standard icon (such as wxICON_INFORMATION) or an icon resource.

wxBITMAP_TYPE_ANI

Windows animated icon file (ANI).

wxBITMAP_TYPE_IFF

IFF bitmap file.

wxBITMAP_TYPE_MACCURSOR

Mac cursor file.

wxBITMAP_TYPE_MACCURSOR_RESOURCE

Mac cursor, to be loaded from the resource part of the executable.

wxBITMAP_TYPE_ANY

Tells the image loading code to figure out the type itself.


    team bbl



    Cross-Platform GUI Programming with wxWidgets
    Cross-Platform GUI Programming with wxWidgets
    ISBN: 0131473816
    EAN: 2147483647
    Year: 2005
    Pages: 262

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net