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. Note that this does not take a fresh copy of the data,
42 but instead makes the internal data point to
{\it bitmap
}'s data. So
43 changing one bitmap will change the other. To make a real copy, you can
47 wxBitmap newBitmap = oldBitmap.GetSubBitmap(
48 wxRect(
0,
0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));
51 \func{}{wxBitmap
}{\param{void*
}{ data
},
\param{int
}{ type
},
\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
53 Creates a bitmap from the given data which is interpreted in platform-dependent
56 \func{}{wxBitmap
}{\param{const char
}{ bits
[]},
\param{int
}{ width
},
\param{int
}{ height
}\\
57 \param{int
}{ depth =
1}}
59 Creates a bitmap from an array of bits.
61 You should only use this function for monochrome bitmaps (
{\it depth
} 1) in
62 portable programs: in this case the
{\it bits
} parameter should contain an XBM
65 For other bit depths, the behaviour is platform dependent: under Windows, the
66 data is passed without any changes to the underlying
{\tt CreateBitmap()
} API.
67 Under other platforms, only monochrome bitmaps may be created using this
68 constructor and
\helpref{wxImage
}{wximage
} should be used for creating colour
69 bitmaps from static data.
71 \func{}{wxBitmap
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
73 Creates a new bitmap. A depth of -
1 indicates the depth of the current screen
74 or visual. Some platforms only support
1 for monochrome and -
1 for the current
75 colour setting. Beginning with version
2.5.4 of wxWidgets a depth of
32 including
76 an alpha channel is supported under MSW, Mac and GTK+.
78 \func{}{wxBitmap
}{\param{const char**
}{ bits
}}
80 Creates a bitmap from XPM data.
82 \func{}{wxBitmap
}{\param{const wxString\&
}{name
},
\param{long
}{ type
}}
84 Loads a bitmap from a file or resource.
86 \func{}{wxBitmap
}{\param{const wxImage\&
}{ img
},
\param{int
}{ depth = -
1}}
88 Creates bitmap object from the image. This has to be done
89 to actually display an image as you cannot draw an image directly on a window.
90 The resulting bitmap will use the provided colour depth (or that of the
91 current system if depth is -
1) which entails that a colour reduction has
94 When in
8-bit mode (PseudoColour mode), the GTK port will use a
color cube created
95 on program start-up to look up colors. This ensures a very fast conversion, but
96 the image quality won't be perfect (and could be better for photo images using more
97 sophisticated dithering algorithms).
99 On Windows, if there is a palette present (set with SetPalette), it will be used when
100 creating the wxBitmap (most useful in
8-bit display mode). On other platforms,
101 the palette is currently ignored.
103 \wxheading{Parameters
}
105 \docparam{bits
}{Specifies an array of pixel values.
}
107 \docparam{width
}{Specifies the width of the bitmap.
}
109 \docparam{height
}{Specifies the height of the bitmap.
}
111 \docparam{depth
}{Specifies the depth of the bitmap. If this is omitted, the display depth of the
114 \docparam{name
}{This can refer to a resource name under MS Windows, or a filename under MS Windows and X.
115 Its meaning is determined by the
{\it type
} parameter.
}
117 \docparam{type
}{May be one of the following:
121 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
122 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP\_RESOURCE}}{Load a Windows bitmap resource from the executable. Windows only.
}
123 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PICT\_RESOURCE}}{Load a PICT image resource from the executable. Mac OS only.
}
124 \twocolitem{\indexit{wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
125 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XBM}}{Load an X bitmap file.
}
126 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XPM}}{Load an XPM bitmap file.
}
129 The validity of these flags depends on the platform and wxWidgets configuration.
130 If all possible wxWidgets settings are used, the Windows platform supports BMP file, BMP resource,
131 XPM data, and XPM. Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
132 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
134 In addition, wxBitmap can read all formats that
\helpref{wxImage
}{wximage
} can, which currently include
135 wxBITMAP
\_TYPE\_JPEG, wxBITMAP
\_TYPE\_TIF, wxBITMAP
\_TYPE\_PNG, wxBITMAP
\_TYPE\_GIF, wxBITMAP
\_TYPE\_PCX,
136 and wxBITMAP
\_TYPE\_PNM. Of course, you must have wxImage handlers loaded.
}
138 \docparam{img
}{Platform-independent wxImage object.
}
142 The first form constructs a bitmap object with no data; an assignment or another member function such as Create
143 or LoadFile must be called subsequently.
145 The second and third forms provide copy constructors. Note that these do not copy the
146 bitmap data, but instead a pointer to the data, keeping a reference count. They are therefore
147 very efficient operations.
149 The fourth form constructs a bitmap from data whose type and value depends on
150 the value of the
{\it type
} argument.
152 The fifth form constructs a (usually monochrome) bitmap from an array of pixel values, under both
155 The sixth form constructs a new bitmap.
157 The seventh form constructs a bitmap from pixmap (XPM) data, if wxWidgets has been configured
158 to incorporate this feature.
160 To use this constructor, you must first include an XPM file. For
161 example, assuming that the file
{\tt mybitmap.xpm
} contains an XPM array
162 of character pointers called mybitmap:
165 #include "mybitmap.xpm"
169 wxBitmap *bitmap = new wxBitmap(mybitmap);
172 The eighth form constructs a bitmap from a file or resource.
{\it name
} can refer
173 to a resource name under MS Windows, or a filename under MS Windows and X.
175 Under Windows,
{\it type
} defaults to wxBITMAP
\_TYPE\_BMP\_RESOURCE.
176 Under X,
{\it type
} defaults to wxBITMAP
\_TYPE\_XPM.
180 \helpref{wxBitmap::LoadFile
}{wxbitmaploadfile
}
182 \pythonnote{Constructors supported by wxPython are:
\par
183 \indented{2cm
}{\begin{twocollist
}
184 \twocolitem{{\bf wxBitmap(name, flag)
}}{Loads a bitmap from a file
}
185 \twocolitem{{\bf wxEmptyBitmap(width, height, depth = -
1)
}}{Creates an
186 empty bitmap with the given specifications
}
187 \twocolitem{{\bf wxBitmapFromXPMData(listOfStrings)
}}{Create a bitmap
188 from a Python list of strings whose contents are XPM data.
}
189 \twocolitem{{\bf wxBitmapFromBits(bits, width, height,
190 depth=-
1)
}}{Create a bitmap from an array of bits contained in a
192 \twocolitem{{\bf wxBitmapFromImage(image, depth=-
1)
}}{Convert a
193 wxImage to a wxBitmap.
}
197 \perlnote{Constructors supported by wxPerl are:
\par
199 \item{Wx::Bitmap->new( width, height, depth = -
1 )
}
200 \item{Wx::Bitmap->new( name, type )
}
201 \item{Wx::Bitmap->new( icon )
}
202 \item{Wx::Bitmap->newFromBits( bits, width, height, depth =
1 )
}
203 \item{Wx::Bitmap->newFromXPM( data )
}
207 \membersection{wxBitmap::
\destruct{wxBitmap
}}\label{wxbitmapdtor
}
209 \func{}{\destruct{wxBitmap
}}{\void}
211 Destroys the wxBitmap object and possibly the underlying bitmap data.
212 Because reference counting is used, the bitmap may not actually be
213 destroyed at this point - only when the reference count is zero will the
216 If the application omits to delete the bitmap explicitly, the bitmap will be
217 destroyed automatically by wxWidgets when the application exits.
219 Do not delete a bitmap that is selected into a memory device context.
221 \membersection{wxBitmap::AddHandler
}\label{wxbitmapaddhandler
}
223 \func{static void
}{AddHandler
}{\param{wxBitmapHandler*
}{ handler
}}
225 Adds a handler to the end of the static list of format handlers.
227 \docparam{handler
}{A new bitmap format handler object. There is usually only one instance
228 of a given handler class in an application session.
}
232 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
234 \membersection{wxBitmap::CleanUpHandlers
}\label{wxbitmapcleanuphandlers
}
236 \func{static void
}{CleanUpHandlers
}{\void}
238 Deletes all bitmap handlers.
240 This function is called by wxWidgets on exit.
242 \membersection{wxBitmap::ConvertToImage
}\label{wxbitmapconverttoimage
}
244 \func{wxImage
}{ConvertToImage
}{\void}
246 Creates an image from a platform-dependent bitmap. This preserves
247 mask information so that bitmaps and images can be converted back
248 and forth without loss in that respect.
250 \membersection{wxBitmap::CopyFromIcon
}\label{wxbitmapcopyfromicon
}
252 \func{bool
}{CopyFromIcon
}{\param{const wxIcon\&
}{ icon
}}
254 Creates the bitmap from an icon.
256 \membersection{wxBitmap::Create
}\label{wxbitmapcreate
}
258 \func{virtual bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
260 Creates a fresh bitmap. If the final argument is omitted, the display depth of
263 \func{virtual bool
}{Create
}{\param{void*
}{ data
},
\param{int
}{ type
},
\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
265 Creates a bitmap from the given data, which can be of arbitrary type.
267 \wxheading{Parameters
}
269 \docparam{width
}{The width of the bitmap in pixels.
}
271 \docparam{height
}{The height of the bitmap in pixels.
}
273 \docparam{depth
}{The depth of the bitmap in pixels. If this is -
1, the screen depth is used.
}
275 \docparam{data
}{Data whose type depends on the value of
{\it type
}.
}
277 \docparam{type
}{A bitmap type identifier - see
\helpref{wxBitmap::wxBitmap
}{wxbitmapctor
} for a list
280 \wxheading{Return value
}
282 true if the call succeeded, false otherwise.
286 The first form works on all platforms. The portability of the second form depends on the
291 \helpref{wxBitmap::wxBitmap
}{wxbitmapctor
}
293 \membersection{wxBitmap::FindHandler
}\label{wxbitmapfindhandler
}
295 \func{static wxBitmapHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
297 Finds the handler with the given name.
299 \func{static wxBitmapHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{wxBitmapType
}{ bitmapType
}}
301 Finds the handler associated with the given extension and type.
303 \func{static wxBitmapHandler*
}{FindHandler
}{\param{wxBitmapType
}{bitmapType
}}
305 Finds the handler associated with the given bitmap type.
307 \docparam{name
}{The handler name.
}
309 \docparam{extension
}{The file extension, such as ``bmp".
}
311 \docparam{bitmapType
}{The bitmap type, such as wxBITMAP
\_TYPE\_BMP.
}
313 \wxheading{Return value
}
315 A pointer to the handler if found, NULL otherwise.
319 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
321 \membersection{wxBitmap::GetDepth
}\label{wxbitmapgetdepth
}
323 \constfunc{int
}{GetDepth
}{\void}
325 Gets the colour depth of the bitmap. A value of
1 indicates a
328 \membersection{wxBitmap::GetHandlers
}\label{wxbitmapgethandlers
}
330 \func{static wxList\&
}{GetHandlers
}{\void}
332 Returns the static list of bitmap format handlers.
336 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
338 \membersection{wxBitmap::GetHeight
}\label{wxbitmapgetheight
}
340 \constfunc{int
}{GetHeight
}{\void}
342 Gets the height of the bitmap in pixels.
344 \membersection{wxBitmap::GetPalette
}\label{wxbitmapgetpalette
}
346 \constfunc{wxPalette*
}{GetPalette
}{\void}
348 Gets the associated palette (if any) which may have been loaded from a file
349 or set for the bitmap.
353 \helpref{wxPalette
}{wxpalette
}
355 \membersection{wxBitmap::GetMask
}\label{wxbitmapgetmask
}
357 \constfunc{wxMask*
}{GetMask
}{\void}
359 Gets the associated mask (if any) which may have been loaded from a file
360 or set for the bitmap.
364 \helpref{wxBitmap::SetMask
}{wxbitmapsetmask
},
\helpref{wxMask
}{wxmask
}
366 \membersection{wxBitmap::GetWidth
}\label{wxbitmapgetwidth
}
368 \constfunc{int
}{GetWidth
}{\void}
370 Gets the width of the bitmap in pixels.
374 \helpref{wxBitmap::GetHeight
}{wxbitmapgetheight
}
376 \membersection{wxBitmap::GetSubBitmap
}\label{wxbitmapgetsubbitmap
}
378 \constfunc{wxBitmap
}{GetSubBitmap
}{\param{const wxRect\&
}{rect
}}
380 Returns a sub bitmap of the current one as long as the rect belongs entirely to
381 the bitmap. This function preserves bit depth and mask information.
383 \membersection{wxBitmap::InitStandardHandlers
}\label{wxbitmapinitstandardhandlers
}
385 \func{static void
}{InitStandardHandlers
}{\void}
387 Adds the standard bitmap format handlers, which, depending on wxWidgets
388 configuration, can be handlers for Windows bitmap, Windows bitmap resource, and XPM.
390 This function is called by wxWidgets on startup.
394 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
396 \membersection{wxBitmap::InsertHandler
}\label{wxbitmapinserthandler
}
398 \func{static void
}{InsertHandler
}{\param{wxBitmapHandler*
}{ handler
}}
400 Adds a handler at the start of the static list of format handlers.
402 \docparam{handler
}{A new bitmap format handler object. There is usually only one instance
403 of a given handler class in an application session.
}
407 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
409 \membersection{wxBitmap::LoadFile
}\label{wxbitmaploadfile
}
411 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{wxBitmapType
}{ type
}}
413 Loads a bitmap from a file or resource.
415 \wxheading{Parameters
}
417 \docparam{name
}{Either a filename or a Windows resource name.
418 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
420 \docparam{type
}{One of the following values:
424 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
425 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP\_RESOURCE}}{Load a Windows bitmap resource from the executable.
}
426 \twocolitem{{\bf wxBITMAP
\_TYPE\_PICT\_RESOURCE}}{Load a PICT image resource from the executable. Mac OS only.
}
427 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
428 \twocolitem{{\bf wxBITMAP
\_TYPE\_XBM}}{Load an X bitmap file.
}
429 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Load an XPM bitmap file.
}
432 The validity of these flags depends on the platform and wxWidgets configuration.
434 In addition, wxBitmap can read all formats that
\helpref{wxImage
}{wximage
} can
435 (wxBITMAP
\_TYPE\_JPEG, wxBITMAP
\_TYPE\_PNG, wxBITMAP
\_TYPE\_GIF, wxBITMAP
\_TYPE\_PCX, wxBITMAP
\_TYPE\_PNM).
436 (Of course you must have wxImage handlers loaded.)
}
438 \wxheading{Return value
}
440 true if the operation succeeded, false otherwise.
444 A palette may be associated with the bitmap if one exists (especially for
445 colour Windows bitmaps), and if the code supports it. You can check
446 if one has been created by using the
\helpref{GetPalette
}{wxbitmapgetpalette
} member.
450 \helpref{wxBitmap::SaveFile
}{wxbitmapsavefile
}
452 \membersection{wxBitmap::Ok
}\label{wxbitmapok
}
454 \constfunc{bool
}{Ok
}{\void}
456 Returns true if bitmap data is present.
458 \membersection{wxBitmap::RemoveHandler
}\label{wxbitmapremovehandler
}
460 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
462 Finds the handler with the given name, and removes it. The handler
465 \docparam{name
}{The handler name.
}
467 \wxheading{Return value
}
469 true if the handler was found and removed, false otherwise.
473 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
475 \membersection{wxBitmap::SaveFile
}\label{wxbitmapsavefile
}
477 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{wxBitmapType
}{ type
},
\param{wxPalette*
}{palette = NULL
}}
479 Saves a bitmap in the named file.
481 \wxheading{Parameters
}
483 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
485 \docparam{type
}{One of the following values:
489 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Save a Windows bitmap file.
}
490 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Save a GIF bitmap file.
}
491 \twocolitem{{\bf wxBITMAP
\_TYPE\_XBM}}{Save an X bitmap file.
}
492 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Save an XPM bitmap file.
}
495 The validity of these flags depends on the platform and wxWidgets configuration.
497 In addition, wxBitmap can save all formats that
\helpref{wxImage
}{wximage
} can
498 (wxBITMAP
\_TYPE\_JPEG, wxBITMAP
\_TYPE\_PNG).
499 (Of course you must have wxImage handlers loaded.)
}
501 \docparam{palette
}{An optional palette used for saving the bitmap.
}
502 % TODO: this parameter should
503 %probably be eliminated; instead the app should set the palette before saving.
505 \wxheading{Return value
}
507 true if the operation succeeded, false otherwise.
511 Depending on how wxWidgets has been configured, not all formats may be available.
515 \helpref{wxBitmap::LoadFile
}{wxbitmaploadfile
}
517 \membersection{wxBitmap::SetDepth
}\label{wxbitmapsetdepth
}
519 \func{void
}{SetDepth
}{\param{int
}{depth
}}
521 Sets the depth member (does not affect the bitmap data).
523 \wxheading{Parameters
}
525 \docparam{depth
}{Bitmap depth.
}
527 \membersection{wxBitmap::SetHeight
}\label{wxbitmapsetheight
}
529 \func{void
}{SetHeight
}{\param{int
}{height
}}
531 Sets the height member (does not affect the bitmap data).
533 \wxheading{Parameters
}
535 \docparam{height
}{Bitmap height in pixels.
}
537 \membersection{wxBitmap::SetMask
}\label{wxbitmapsetmask
}
539 \func{void
}{SetMask
}{\param{wxMask*
}{mask
}}
541 Sets the mask for this bitmap.
545 The bitmap object owns the mask once this has been called.
549 \helpref{wxBitmap::GetMask
}{wxbitmapgetmask
},
\helpref{wxMask
}{wxmask
}
551 %% VZ: this function is an implementation detail and shouldn't be documented
552 %%\membersection{wxBitmap::SetOk}\label{wxbitmapsetok}
554 %%\func{void}{SetOk}{\param{int }{isOk}}
556 %%Sets the validity member (does not affect the bitmap data).
558 %%\wxheading{Parameters}
560 %%\docparam{isOk}{Validity flag.}
562 \membersection{wxBitmap::SetPalette
}\label{wxbitmapsetpalette
}
564 \func{void
}{SetPalette
}{\param{const wxPalette\&
}{palette
}}
566 Sets the associated palette. (Not implemented under GTK+).
568 \wxheading{Parameters
}
570 \docparam{palette
}{The palette to set.
}
574 \helpref{wxPalette
}{wxpalette
}
576 \membersection{wxBitmap::SetWidth
}\label{wxbitmapsetwidth
}
578 \func{void
}{SetWidth
}{\param{int
}{width
}}
580 Sets the width member (does not affect the bitmap data).
582 \wxheading{Parameters
}
584 \docparam{width
}{Bitmap width in pixels.
}
586 \membersection{wxBitmap::operator $=$
}\label{wxbitmapassign
}
588 \func{wxBitmap\&
}{operator $=$
}{\param{const wxBitmap\&
}{bitmap
}}
590 Assignment operator. This operator does not copy any data, but instead
591 passes a pointer to the data in
{\it bitmap
} and increments a reference
592 counter. It is a fast operation.
594 \wxheading{Parameters
}
596 \docparam{bitmap
}{Bitmap to assign.
}
598 \wxheading{Return value
}
600 Returns 'this' object.
602 \membersection{wxBitmap::operator $==$
}\label{wxbitmapequal
}
604 \func{bool
}{operator $==$
}{\param{const wxBitmap\&
}{bitmap
}}
606 Equality operator. This operator tests whether the internal data pointers are
609 \wxheading{Parameters
}
611 \docparam{bitmap
}{Bitmap to compare with 'this'
}
613 \wxheading{Return value
}
615 Returns true if the bitmaps were effectively equal, false otherwise.
617 \membersection{wxBitmap::operator $!=$
}\label{wxbitmapnotequal
}
619 \func{bool
}{operator $!=$
}{\param{const wxBitmap\&
}{bitmap
}}
621 Inequality operator. This operator tests whether the internal data pointers are
622 unequal (a fast test).
624 \wxheading{Parameters
}
626 \docparam{bitmap
}{Bitmap to compare with 'this'
}
628 \wxheading{Return value
}
630 Returns true if the bitmaps were unequal, false otherwise.