1 \section{\class{wxBitmap
}}\label{wxbitmap
}
3 %\overview{Overview}{wxbitmapoverview}
5 This class encapsulates the concept of a platform-dependent bitmap,
6 either monochrome or colour or colour with alpha channel support.
8 \wxheading{Derived from
}
10 \helpref{wxGDIObject
}{wxgdiobject
}\\
11 \helpref{wxObject
}{wxobject
}
13 \wxheading{Include files
}
17 \wxheading{Predefined objects
}
25 \helpref{wxBitmap overview
}{wxbitmapoverview
},
26 \helpref{supported bitmap file formats
}{supportedbitmapformats
},
27 \helpref{wxDC::Blit
}{wxdcblit
},
28 \helpref{wxIcon
}{wxicon
},
\helpref{wxCursor
}{wxcursor
},
\helpref{wxBitmap
}{wxbitmap
},
29 \helpref{wxMemoryDC
}{wxmemorydc
}
31 \latexignore{\rtfignore{\wxheading{Members
}}}
33 \membersection{wxBitmap::wxBitmap
}\label{wxbitmapctor
}
35 \func{}{wxBitmap
}{\void}
39 \func{}{wxBitmap
}{\param{const wxBitmap\&
}{bitmap
}}
41 Copy constructor, uses
\helpref{reference counting
}{trefcount
}.
42 To make a real copy, you can use:
45 wxBitmap newBitmap = oldBitmap.GetSubBitmap(
46 wxRect(
0,
0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));
49 \func{}{wxBitmap
}{\param{const void*
}{ data
},
\param{int
}{ type
},
\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
51 Creates a bitmap from the given data which is interpreted in platform-dependent
54 \func{}{wxBitmap
}{\param{const char
}{ bits
[]},
\param{int
}{ width
},
\param{int
}{ height
}\\
55 \param{int
}{ depth =
1}}
57 Creates a bitmap from an array of bits.
59 You should only use this function for monochrome bitmaps (
{\it depth
} 1) in
60 portable programs: in this case the
{\it bits
} parameter should contain an XBM
63 For other bit depths, the behaviour is platform dependent: under Windows, the
64 data is passed without any changes to the underlying
{\tt CreateBitmap()
} API.
65 Under other platforms, only monochrome bitmaps may be created using this
66 constructor and
\helpref{wxImage
}{wximage
} should be used for creating colour
67 bitmaps from static data.
69 \func{}{wxBitmap
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
71 Creates a new bitmap. A depth of -
1 indicates the depth of the current screen
72 or visual. Some platforms only support
1 for monochrome and -
1 for the current
73 colour setting. Beginning with version
2.5.4 of wxWidgets a depth of
32 including
74 an alpha channel is supported under MSW, Mac and GTK+.
76 \func{}{wxBitmap
}{\param{const char* const*
}{ bits
}}
78 Creates a bitmap from XPM data.
80 \func{}{wxBitmap
}{\param{const wxString\&
}{name
},
\param{long
}{ type
}}
82 Loads a bitmap from a file or resource.
84 \func{}{wxBitmap
}{\param{const wxImage\&
}{ img
},
\param{int
}{ depth = -
1}}
86 Creates bitmap object from the image. This has to be done
87 to actually display an image as you cannot draw an image directly on a window.
88 The resulting bitmap will use the provided colour depth (or that of the
89 current system if depth is -
1) which entails that a colour reduction has
92 When in
8-bit mode (PseudoColour mode), the GTK port will use a
color cube created
93 on program start-up to look up colors. This ensures a very fast conversion, but
94 the image quality won't be perfect (and could be better for photo images using more
95 sophisticated dithering algorithms).
97 On Windows, if there is a palette present (set with SetPalette), it will be used when
98 creating the wxBitmap (most useful in
8-bit display mode). On other platforms,
99 the palette is currently ignored.
101 \wxheading{Parameters
}
103 \docparam{bits
}{Specifies an array of pixel values.
}
105 \docparam{width
}{Specifies the width of the bitmap.
}
107 \docparam{height
}{Specifies the height of the bitmap.
}
109 \docparam{depth
}{Specifies the depth of the bitmap. If this is omitted, the display depth of the
112 \docparam{name
}{This can refer to a resource name under MS Windows, or a filename under MS Windows and X.
113 Its meaning is determined by the
{\it type
} parameter.
}
115 \docparam{type
}{May be one of the following:
119 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
120 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP\_RESOURCE}}{Load a Windows bitmap resource from the executable. Windows only.
}
121 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PICT\_RESOURCE}}{Load a PICT image resource from the executable. Mac OS only.
}
122 \twocolitem{\indexit{wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
123 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XBM}}{Load an X bitmap file.
}
124 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XPM}}{Load an XPM bitmap file.
}
127 The validity of these flags depends on the platform and wxWidgets configuration.
128 If all possible wxWidgets settings are used, the Windows platform supports BMP file, BMP resource,
129 XPM data, and XPM. Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
130 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
132 In addition, wxBitmap can read all formats that
\helpref{wxImage
}{wximage
} can, which currently include
133 wxBITMAP
\_TYPE\_JPEG, wxBITMAP
\_TYPE\_TIF, wxBITMAP
\_TYPE\_PNG, wxBITMAP
\_TYPE\_GIF, wxBITMAP
\_TYPE\_PCX,
134 and wxBITMAP
\_TYPE\_PNM. Of course, you must have wxImage handlers loaded.
}
136 \docparam{img
}{Platform-independent wxImage object.
}
140 The first form constructs a bitmap object with no data; an assignment or another member function such as Create
141 or LoadFile must be called subsequently.
143 The second and third forms provide copy constructors. Note that these do not copy the
144 bitmap data, but instead a pointer to the data, keeping a reference count. They are therefore
145 very efficient operations.
147 The fourth form constructs a bitmap from data whose type and value depends on
148 the value of the
{\it type
} argument.
150 The fifth form constructs a (usually monochrome) bitmap from an array of pixel values, under both
153 The sixth form constructs a new bitmap.
155 The seventh form constructs a bitmap from pixmap (XPM) data, if wxWidgets has been configured
156 to incorporate this feature.
158 To use this constructor, you must first include an XPM file. For
159 example, assuming that the file
{\tt mybitmap.xpm
} contains an XPM array
160 of character pointers called mybitmap:
163 #include "mybitmap.xpm"
167 wxBitmap *bitmap = new wxBitmap(mybitmap);
170 The eighth form constructs a bitmap from a file or resource.
{\it name
} can refer
171 to a resource name under MS Windows, or a filename under MS Windows and X.
173 Under Windows,
{\it type
} defaults to wxBITMAP
\_TYPE\_BMP\_RESOURCE.
174 Under X,
{\it type
} defaults to wxBITMAP
\_TYPE\_XPM.
178 \helpref{wxBitmap::LoadFile
}{wxbitmaploadfile
}
180 \pythonnote{Constructors supported by wxPython are:
\par
181 \indented{2cm
}{\begin{twocollist
}
182 \twocolitem{{\bf wxBitmap(name, flag)
}}{Loads a bitmap from a file
}
183 \twocolitem{{\bf wxEmptyBitmap(width, height, depth = -
1)
}}{Creates an
184 empty bitmap with the given specifications
}
185 \twocolitem{{\bf wxBitmapFromXPMData(listOfStrings)
}}{Create a bitmap
186 from a Python list of strings whose contents are XPM data.
}
187 \twocolitem{{\bf wxBitmapFromBits(bits, width, height,
188 depth=-
1)
}}{Create a bitmap from an array of bits contained in a
190 \twocolitem{{\bf wxBitmapFromImage(image, depth=-
1)
}}{Convert a
191 wxImage to a wxBitmap.
}
195 \perlnote{Constructors supported by wxPerl are:
\par
197 \item{Wx::Bitmap->new( width, height, depth = -
1 )
}
198 \item{Wx::Bitmap->new( name, type )
}
199 \item{Wx::Bitmap->new( icon )
}
200 \item{Wx::Bitmap->newFromBits( bits, width, height, depth =
1 )
}
201 \item{Wx::Bitmap->newFromXPM( data )
}
205 \membersection{wxBitmap::
\destruct{wxBitmap
}}\label{wxbitmapdtor
}
207 \func{}{\destruct{wxBitmap
}}{\void}
209 Destroys the wxBitmap object and possibly the underlying bitmap data.
210 Because reference counting is used, the bitmap may not actually be
211 destroyed at this point - only when the reference count is zero will the
214 If the application omits to delete the bitmap explicitly, the bitmap will be
215 destroyed automatically by wxWidgets when the application exits.
217 Do not delete a bitmap that is selected into a memory device context.
219 \membersection{wxBitmap::AddHandler
}\label{wxbitmapaddhandler
}
221 \func{static void
}{AddHandler
}{\param{wxBitmapHandler*
}{ handler
}}
223 Adds a handler to the end of the static list of format handlers.
225 \docparam{handler
}{A new bitmap format handler object. There is usually only one instance
226 of a given handler class in an application session.
}
230 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
232 \membersection{wxBitmap::CleanUpHandlers
}\label{wxbitmapcleanuphandlers
}
234 \func{static void
}{CleanUpHandlers
}{\void}
236 Deletes all bitmap handlers.
238 This function is called by wxWidgets on exit.
240 \membersection{wxBitmap::ConvertToImage
}\label{wxbitmapconverttoimage
}
242 \func{wxImage
}{ConvertToImage
}{\void}
244 Creates an image from a platform-dependent bitmap. This preserves
245 mask information so that bitmaps and images can be converted back
246 and forth without loss in that respect.
248 \membersection{wxBitmap::CopyFromIcon
}\label{wxbitmapcopyfromicon
}
250 \func{bool
}{CopyFromIcon
}{\param{const wxIcon\&
}{ icon
}}
252 Creates the bitmap from an icon.
254 \membersection{wxBitmap::Create
}\label{wxbitmapcreate
}
256 \func{virtual bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
258 Creates a fresh bitmap. If the final argument is omitted, the display depth of
261 \func{virtual bool
}{Create
}{\param{const void*
}{ data
},
\param{int
}{ type
},
\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
263 Creates a bitmap from the given data, which can be of arbitrary type.
265 \wxheading{Parameters
}
267 \docparam{width
}{The width of the bitmap in pixels.
}
269 \docparam{height
}{The height of the bitmap in pixels.
}
271 \docparam{depth
}{The depth of the bitmap in pixels. If this is -
1, the screen depth is used.
}
273 \docparam{data
}{Data whose type depends on the value of
{\it type
}.
}
275 \docparam{type
}{A bitmap type identifier - see
\helpref{wxBitmap::wxBitmap
}{wxbitmapctor
} for a list
278 \wxheading{Return value
}
280 true if the call succeeded, false otherwise.
284 The first form works on all platforms. The portability of the second form depends on the
289 \helpref{wxBitmap::wxBitmap
}{wxbitmapctor
}
291 \membersection{wxBitmap::FindHandler
}\label{wxbitmapfindhandler
}
293 \func{static wxBitmapHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
295 Finds the handler with the given name.
297 \func{static wxBitmapHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{wxBitmapType
}{ bitmapType
}}
299 Finds the handler associated with the given extension and type.
301 \func{static wxBitmapHandler*
}{FindHandler
}{\param{wxBitmapType
}{bitmapType
}}
303 Finds the handler associated with the given bitmap type.
305 \docparam{name
}{The handler name.
}
307 \docparam{extension
}{The file extension, such as ``bmp".
}
309 \docparam{bitmapType
}{The bitmap type, such as wxBITMAP
\_TYPE\_BMP.
}
311 \wxheading{Return value
}
313 A pointer to the handler if found, NULL otherwise.
317 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
319 \membersection{wxBitmap::GetDepth
}\label{wxbitmapgetdepth
}
321 \constfunc{int
}{GetDepth
}{\void}
323 Gets the colour depth of the bitmap. A value of
1 indicates a
326 \membersection{wxBitmap::GetHandlers
}\label{wxbitmapgethandlers
}
328 \func{static wxList\&
}{GetHandlers
}{\void}
330 Returns the static list of bitmap format handlers.
334 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
336 \membersection{wxBitmap::GetHeight
}\label{wxbitmapgetheight
}
338 \constfunc{int
}{GetHeight
}{\void}
340 Gets the height of the bitmap in pixels.
342 \membersection{wxBitmap::GetPalette
}\label{wxbitmapgetpalette
}
344 \constfunc{wxPalette*
}{GetPalette
}{\void}
346 Gets the associated palette (if any) which may have been loaded from a file
347 or set for the bitmap.
351 \helpref{wxPalette
}{wxpalette
}
353 \membersection{wxBitmap::GetMask
}\label{wxbitmapgetmask
}
355 \constfunc{wxMask*
}{GetMask
}{\void}
357 Gets the associated mask (if any) which may have been loaded from a file
358 or set for the bitmap.
362 \helpref{wxBitmap::SetMask
}{wxbitmapsetmask
},
\helpref{wxMask
}{wxmask
}
364 \membersection{wxBitmap::GetWidth
}\label{wxbitmapgetwidth
}
366 \constfunc{int
}{GetWidth
}{\void}
368 Gets the width of the bitmap in pixels.
372 \helpref{wxBitmap::GetHeight
}{wxbitmapgetheight
}
374 \membersection{wxBitmap::GetSubBitmap
}\label{wxbitmapgetsubbitmap
}
376 \constfunc{wxBitmap
}{GetSubBitmap
}{\param{const wxRect\&
}{rect
}}
378 Returns a sub bitmap of the current one as long as the rect belongs entirely to
379 the bitmap. This function preserves bit depth and mask information.
381 \membersection{wxBitmap::InitStandardHandlers
}\label{wxbitmapinitstandardhandlers
}
383 \func{static void
}{InitStandardHandlers
}{\void}
385 Adds the standard bitmap format handlers, which, depending on wxWidgets
386 configuration, can be handlers for Windows bitmap, Windows bitmap resource, and XPM.
388 This function is called by wxWidgets on startup.
392 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
394 \membersection{wxBitmap::InsertHandler
}\label{wxbitmapinserthandler
}
396 \func{static void
}{InsertHandler
}{\param{wxBitmapHandler*
}{ handler
}}
398 Adds a handler at the start of the static list of format handlers.
400 \docparam{handler
}{A new bitmap format handler object. There is usually only one instance
401 of a given handler class in an application session.
}
405 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
407 \membersection{wxBitmap::LoadFile
}\label{wxbitmaploadfile
}
409 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{wxBitmapType
}{ type
}}
411 Loads a bitmap from a file or resource.
413 \wxheading{Parameters
}
415 \docparam{name
}{Either a filename or a Windows resource name.
416 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
418 \docparam{type
}{One of the following values:
422 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
423 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP\_RESOURCE}}{Load a Windows bitmap resource from the executable.
}
424 \twocolitem{{\bf wxBITMAP
\_TYPE\_PICT\_RESOURCE}}{Load a PICT image resource from the executable. Mac OS only.
}
425 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
426 \twocolitem{{\bf wxBITMAP
\_TYPE\_XBM}}{Load an X bitmap file.
}
427 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Load an XPM bitmap file.
}
430 The validity of these flags depends on the platform and wxWidgets configuration.
432 In addition, wxBitmap can read all formats that
\helpref{wxImage
}{wximage
} can
433 (wxBITMAP
\_TYPE\_JPEG, wxBITMAP
\_TYPE\_PNG, wxBITMAP
\_TYPE\_GIF, wxBITMAP
\_TYPE\_PCX, wxBITMAP
\_TYPE\_PNM).
434 (Of course you must have wxImage handlers loaded.)
}
436 \wxheading{Return value
}
438 true if the operation succeeded, false otherwise.
442 A palette may be associated with the bitmap if one exists (especially for
443 colour Windows bitmaps), and if the code supports it. You can check
444 if one has been created by using the
\helpref{GetPalette
}{wxbitmapgetpalette
} member.
448 \helpref{wxBitmap::SaveFile
}{wxbitmapsavefile
}
450 \membersection{wxBitmap::IsOk
}\label{wxbitmapisok
}
452 \constfunc{bool
}{IsOk
}{\void}
454 Returns true if bitmap data is present.
456 \membersection{wxBitmap::RemoveHandler
}\label{wxbitmapremovehandler
}
458 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
460 Finds the handler with the given name, and removes it. The handler
463 \docparam{name
}{The handler name.
}
465 \wxheading{Return value
}
467 true if the handler was found and removed, false otherwise.
471 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
473 \membersection{wxBitmap::SaveFile
}\label{wxbitmapsavefile
}
475 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{wxBitmapType
}{ type
},
\param{wxPalette*
}{palette = NULL
}}
477 Saves a bitmap in the named file.
479 \wxheading{Parameters
}
481 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
483 \docparam{type
}{One of the following values:
487 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Save a Windows bitmap file.
}
488 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Save a GIF bitmap file.
}
489 \twocolitem{{\bf wxBITMAP
\_TYPE\_XBM}}{Save an X bitmap file.
}
490 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Save an XPM bitmap file.
}
493 The validity of these flags depends on the platform and wxWidgets configuration.
495 In addition, wxBitmap can save all formats that
\helpref{wxImage
}{wximage
} can
496 (wxBITMAP
\_TYPE\_JPEG, wxBITMAP
\_TYPE\_PNG).
497 (Of course you must have wxImage handlers loaded.)
}
499 \docparam{palette
}{An optional palette used for saving the bitmap.
}
500 % TODO: this parameter should
501 %probably be eliminated; instead the app should set the palette before saving.
503 \wxheading{Return value
}
505 true if the operation succeeded, false otherwise.
509 Depending on how wxWidgets has been configured, not all formats may be available.
513 \helpref{wxBitmap::LoadFile
}{wxbitmaploadfile
}
515 \membersection{wxBitmap::SetDepth
}\label{wxbitmapsetdepth
}
517 \func{void
}{SetDepth
}{\param{int
}{depth
}}
519 Sets the depth member (does not affect the bitmap data).
521 \wxheading{Parameters
}
523 \docparam{depth
}{Bitmap depth.
}
525 \membersection{wxBitmap::SetHeight
}\label{wxbitmapsetheight
}
527 \func{void
}{SetHeight
}{\param{int
}{height
}}
529 Sets the height member (does not affect the bitmap data).
531 \wxheading{Parameters
}
533 \docparam{height
}{Bitmap height in pixels.
}
535 \membersection{wxBitmap::SetMask
}\label{wxbitmapsetmask
}
537 \func{void
}{SetMask
}{\param{wxMask*
}{mask
}}
539 Sets the mask for this bitmap.
543 The bitmap object owns the mask once this has been called.
547 \helpref{wxBitmap::GetMask
}{wxbitmapgetmask
},
\helpref{wxMask
}{wxmask
}
549 %% VZ: this function is an implementation detail and shouldn't be documented
550 %%\membersection{wxBitmap::SetOk}\label{wxbitmapsetok}
552 %%\func{void}{SetOk}{\param{int }{isOk}}
554 %%Sets the validity member (does not affect the bitmap data).
556 %%\wxheading{Parameters}
558 %%\docparam{isOk}{Validity flag.}
560 \membersection{wxBitmap::SetPalette
}\label{wxbitmapsetpalette
}
562 \func{void
}{SetPalette
}{\param{const wxPalette\&
}{palette
}}
564 Sets the associated palette. (Not implemented under GTK+).
566 \wxheading{Parameters
}
568 \docparam{palette
}{The palette to set.
}
572 \helpref{wxPalette
}{wxpalette
}
574 \membersection{wxBitmap::SetWidth
}\label{wxbitmapsetwidth
}
576 \func{void
}{SetWidth
}{\param{int
}{width
}}
578 Sets the width member (does not affect the bitmap data).
580 \wxheading{Parameters
}
582 \docparam{width
}{Bitmap width in pixels.
}
584 \membersection{wxBitmap::operator $=$
}\label{wxbitmapassign
}
586 \func{wxBitmap\&
}{operator $=$
}{\param{const wxBitmap\&
}{bitmap
}}
588 Assignment operator, using
\helpref{reference counting
}{trefcount
}.
590 \wxheading{Parameters
}
592 \docparam{bitmap
}{Bitmap to assign.
}
594 \wxheading{Return value
}
596 Returns 'this' object.
598 \membersection{wxBitmap::operator $==$
}\label{wxbitmapequal
}
600 \func{bool
}{operator $==$
}{\param{const wxBitmap\&
}{bitmap
}}
602 Equality operator. This operator tests whether the internal data pointers are
605 \wxheading{Parameters
}
607 \docparam{bitmap
}{Bitmap to compare with 'this'
}
609 \wxheading{Return value
}
611 Returns true if the bitmaps were effectively equal, false otherwise.
613 \membersection{wxBitmap::operator $!=$
}\label{wxbitmapnotequal
}
615 \func{bool
}{operator $!=$
}{\param{const wxBitmap\&
}{bitmap
}}
617 Inequality operator. This operator tests whether the internal data pointers are
618 unequal (a fast test).
620 \wxheading{Parameters
}
622 \docparam{bitmap
}{Bitmap to compare with 'this'
}
624 \wxheading{Return value
}
626 Returns true if the bitmaps were unequal, false otherwise.