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.
8 \wxheading{Derived from
}
10 \helpref{wxGDIObject
}{wxgdiobject
}\\
11 \helpref{wxObject
}{wxobject
}
13 \wxheading{Include file
}
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{wxbitmapconstr
}
35 \func{}{wxBitmap
}{\void}
39 \func{}{wxBitmap
}{\param{const wxBitmap\&
}{bitmap
}}
43 \func{}{wxBitmap
}{\param{void*
}{ data
},
\param{int
}{ type
},
\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
45 Creates a bitmap from the given data which is interpreted in platform-dependent
48 \func{}{wxBitmap
}{\param{const char
}{ bits
[]},
\param{int
}{ width
},
\param{int
}{ height
}\\
49 \param{int
}{ depth =
1}}
51 Creates a bitmap from an array of bits.
53 You should only use this function for monochrome bitmaps (
{\it depth
} 1) in
54 portable programs: in this case the
{\it bits
} parameter should contain an XBM
57 For other bit depths, the behaviour is platform dependent: under Windows, the
58 data is passed without any changes to the underlying
{\tt CreateBitmap()
} API.
59 Under other platforms, only monochrome bitmaps may be created using this
60 constructor and
\helpref{wxImage
}{wximage
} should be used for creating colour
61 bitmaps from static data.
63 \func{}{wxBitmap
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
65 Creates a new bitmap. A depth of -
1 indicates the depth of the current screen
66 or visual. Some platforms only support
1 for monochrome and -
1 for the current
69 \func{}{wxBitmap
}{\param{const char**
}{ bits
}}
71 Creates a bitmap from XPM data.
73 \func{}{wxBitmap
}{\param{const wxString\&
}{name
},
\param{long
}{ type
}}
75 Loads a bitmap from a file or resource.
77 \func{}{wxBitmap
}{\param{const wxImage\&
}{ img
},
\param{int
}{ depth = -
1}}
79 Creates bitmap object from the image. This has to be done
80 to actually display an image as you cannot draw an image directly on a window.
81 The resulting bitmap will use the provided colour depth (or that of the
82 current system if depth is -
1) which entails that a colour reduction has
85 When in
8-bit mode (PseudoColour mode), the GTK port will use a
color cube created
86 on program start-up to look up colors. This ensures a very fast conversion, but
87 the image quality won't be perfect (and could be better for photo images using more
88 sophisticated dithering algorithms).
90 On Windows, if there is a palette present (set with SetPalette), it will be used when
91 creating the wxBitmap (most useful in
8-bit display mode). On other platforms,
92 the palette is currently ignored.
94 \wxheading{Parameters
}
96 \docparam{bits
}{Specifies an array of pixel values.
}
98 \docparam{width
}{Specifies the width of the bitmap.
}
100 \docparam{height
}{Specifies the height of the bitmap.
}
102 \docparam{depth
}{Specifies the depth of the bitmap. If this is omitted, the display depth of the
105 \docparam{name
}{This can refer to a resource name under MS Windows, or a filename under MS Windows and X.
106 Its meaning is determined by the
{\it type
} parameter.
}
108 \docparam{type
}{May be one of the following:
112 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
113 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP\_RESOURCE}}{Load a Windows bitmap from the resource database.
}
114 \twocolitem{\indexit{wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
115 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XBM}}{Load an X bitmap file.
}
116 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XPM}}{Load an XPM bitmap file.
}
117 \twocolitem{\indexit{wxBITMAP
\_TYPE\_RESOURCE}}{Load a Windows resource name.
}
120 The validity of these flags depends on the platform and wxWindows configuration.
121 If all possible wxWindows settings are used, the Windows platform supports BMP file, BMP resource,
122 XPM data, and XPM. Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
123 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
125 In addition, wxBitmap can read all formats that
\helpref{wxImage
}{wximage
} can, which currently include
126 wxBITMAP
\_TYPE\_JPEG, wxBITMAP
\_TYPE\_TIF, wxBITMAP
\_TYPE\_PNG, wxBITMAP
\_TYPE\_GIF, wxBITMAP
\_TYPE\_PCX,
127 and wxBITMAP
\_TYPE\_PNM. Of course, you must have wxImage handlers loaded.
}
129 \docparam{img
}{Platform-independent wxImage object.
}
133 The first form constructs a bitmap object with no data; an assignment or another member function such as Create
134 or LoadFile must be called subsequently.
136 The second and third forms provide copy constructors. Note that these do not copy the
137 bitmap data, but instead a pointer to the data, keeping a reference count. They are therefore
138 very efficient operations.
140 The fourth form constructs a bitmap from data whose type and value depends on
141 the value of the
{\it type
} argument.
143 The fifth form constructs a (usually monochrome) bitmap from an array of pixel values, under both
146 The sixth form constructs a new bitmap.
148 The seventh form constructs a bitmap from pixmap (XPM) data, if wxWindows has been configured
149 to incorporate this feature.
151 To use this constructor, you must first include an XPM file. For
152 example, assuming that the file
{\tt mybitmap.xpm
} contains an XPM array
153 of character pointers called mybitmap:
156 #include "mybitmap.xpm"
160 wxBitmap *bitmap = new wxBitmap(mybitmap);
163 The eighth form constructs a bitmap from a file or resource.
{\it name
} can refer
164 to a resource name under MS Windows, or a filename under MS Windows and X.
166 Under Windows,
{\it type
} defaults to wxBITMAP
\_TYPE\_BMP\_RESOURCE.
167 Under X,
{\it type
} defaults to wxBITMAP
\_TYPE\_XPM.
171 \helpref{wxBitmap::LoadFile
}{wxbitmaploadfile
}
173 \pythonnote{Constructors supported by wxPython are:
\par
174 \indented{2cm
}{\begin{twocollist
}
175 \twocolitem{{\bf wxBitmap(name, flag)
}}{Loads a bitmap from a file
}
176 \twocolitem{{\bf wxEmptyBitmap(width, height, depth = -
1)
}}{Creates an
177 empty bitmap with the given specifications
}
178 \twocolitem{{\bf wxBitmapFromXPMData(listOfStrings)
}}{Create a bitmap
179 from a Python list of strings whose contents are XPM data.
}
180 \twocolitem{{\bf wxBitmapFromBits(bits, width, height,
181 depth=-
1)
}}{Create a bitmap from an array of bits contained in a
183 \twocolitem{{\bf wxBitmapFromImage(image, depth=-
1)
}}{Convert a
184 wxImage to a wxBitmap.
}
188 \perlnote{Constructors supported by wxPerl are:
\par
190 \item{Wx::Bitmap->new( width, height, depth = -
1 )
}
191 \item{Wx::Bitmap->new( name, type )
}
192 \item{Wx::Bitmap->new( icon )
}
193 \item{Wx::Bitmap->newFromBits( bits, width, height, depth =
1 )
}
194 \item{Wx::Bitmap->newFromXPM( data )
}
198 \membersection{wxBitmap::
\destruct{wxBitmap
}}
200 \func{}{\destruct{wxBitmap
}}{\void}
202 Destroys the wxBitmap object and possibly the underlying bitmap data.
203 Because reference counting is used, the bitmap may not actually be
204 destroyed at this point - only when the reference count is zero will the
207 If the application omits to delete the bitmap explicitly, the bitmap will be
208 destroyed automatically by wxWindows when the application exits.
210 Do not delete a bitmap that is selected into a memory device context.
212 \membersection{wxBitmap::AddHandler
}\label{wxbitmapaddhandler
}
214 \func{static void
}{AddHandler
}{\param{wxBitmapHandler*
}{ handler
}}
216 Adds a handler to the end of the static list of format handlers.
218 \docparam{handler
}{A new bitmap format handler object. There is usually only one instance
219 of a given handler class in an application session.
}
223 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
225 \membersection{wxBitmap::CleanUpHandlers
}
227 \func{static void
}{CleanUpHandlers
}{\void}
229 Deletes all bitmap handlers.
231 This function is called by wxWindows on exit.
233 \membersection{wxBitmap::ConvertToImage
}\label{wxbitmapconverttoimage
}
235 \func{wxImage
}{ConvertToImage
}{\void}
237 Creates an image from a platform-dependent bitmap. This preserves
238 mask information so that bitmaps and images can be converted back
239 and forth without loss in that respect.
241 \membersection{wxBitmap::Create
}\label{wxbitmapcreate
}
243 \func{virtual bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
245 Creates a fresh bitmap. If the final argument is omitted, the display depth of
248 \func{virtual bool
}{Create
}{\param{void*
}{ data
},
\param{int
}{ type
},
\param{int
}{ width
},
\param{int
}{ height
},
\param{int
}{ depth = -
1}}
250 Creates a bitmap from the given data, which can be of arbitrary type.
252 \wxheading{Parameters
}
254 \docparam{width
}{The width of the bitmap in pixels.
}
256 \docparam{height
}{The height of the bitmap in pixels.
}
258 \docparam{depth
}{The depth of the bitmap in pixels. If this is -
1, the screen depth is used.
}
260 \docparam{data
}{Data whose type depends on the value of
{\it type
}.
}
262 \docparam{type
}{A bitmap type identifier - see
\helpref{wxBitmap::wxBitmap
}{wxbitmapconstr
} for a list
265 \wxheading{Return value
}
267 TRUE if the call succeeded, FALSE otherwise.
271 The first form works on all platforms. The portability of the second form depends on the
276 \helpref{wxBitmap::wxBitmap
}{wxbitmapconstr
}
278 \membersection{wxBitmap::FindHandler
}
280 \func{static wxBitmapHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
282 Finds the handler with the given name.
284 \func{static wxBitmapHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ bitmapType
}}
286 Finds the handler associated with the given extension and type.
288 \func{static wxBitmapHandler*
}{FindHandler
}{\param{long
}{bitmapType
}}
290 Finds the handler associated with the given bitmap type.
292 \docparam{name
}{The handler name.
}
294 \docparam{extension
}{The file extension, such as ``bmp".
}
296 \docparam{bitmapType
}{The bitmap type, such as wxBITMAP
\_TYPE\_BMP.
}
298 \wxheading{Return value
}
300 A pointer to the handler if found, NULL otherwise.
304 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
306 \membersection{wxBitmap::GetDepth
}
308 \constfunc{int
}{GetDepth
}{\void}
310 Gets the colour depth of the bitmap. A value of
1 indicates a
313 \membersection{wxBitmap::GetHandlers
}
315 \func{static wxList\&
}{GetHandlers
}{\void}
317 Returns the static list of bitmap format handlers.
321 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
323 \membersection{wxBitmap::GetHeight
}\label{wxbitmapgetheight
}
325 \constfunc{int
}{GetHeight
}{\void}
327 Gets the height of the bitmap in pixels.
329 \membersection{wxBitmap::GetPalette
}\label{wxbitmapgetpalette
}
331 \constfunc{wxPalette*
}{GetPalette
}{\void}
333 Gets the associated palette (if any) which may have been loaded from a file
334 or set for the bitmap.
338 \helpref{wxPalette
}{wxpalette
}
340 \membersection{wxBitmap::GetMask
}\label{wxbitmapgetmask
}
342 \constfunc{wxMask*
}{GetMask
}{\void}
344 Gets the associated mask (if any) which may have been loaded from a file
345 or set for the bitmap.
349 \helpref{wxBitmap::SetMask
}{wxbitmapsetmask
},
\helpref{wxMask
}{wxmask
}
351 \membersection{wxBitmap::GetWidth
}\label{wxbitmapgetwidth
}
353 \constfunc{int
}{GetWidth
}{\void}
355 Gets the width of the bitmap in pixels.
359 \helpref{wxBitmap::GetHeight
}{wxbitmapgetheight
}
361 \membersection{wxBitmap::GetSubBitmap
}\label{wxbitmapgetsubbitmap
}
363 \constfunc{wxBitmap
}{GetSubBitmap
}{\param{const wxRect\&
}{rect
}}
365 Returns a sub bitmap of the current one as long as the rect belongs entirely to
366 the bitmap. This function preserves bit depth and mask information.
368 \membersection{wxBitmap::InitStandardHandlers
}
370 \func{static void
}{InitStandardHandlers
}{\void}
372 Adds the standard bitmap format handlers, which, depending on wxWindows
373 configuration, can be handlers for Windows bitmap, Windows bitmap resource, and XPM.
375 This function is called by wxWindows on startup.
379 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
381 \membersection{wxBitmap::InsertHandler
}
383 \func{static void
}{InsertHandler
}{\param{wxBitmapHandler*
}{ handler
}}
385 Adds a handler at the start of the static list of format handlers.
387 \docparam{handler
}{A new bitmap format handler object. There is usually only one instance
388 of a given handler class in an application session.
}
392 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
394 \membersection{wxBitmap::LoadFile
}\label{wxbitmaploadfile
}
396 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type
}}
398 Loads a bitmap from a file or resource.
400 \wxheading{Parameters
}
402 \docparam{name
}{Either a filename or a Windows resource name.
403 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
405 \docparam{type
}{One of the following values:
409 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
410 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP\_RESOURCE}}{Load a Windows bitmap from the resource database.
}
411 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
412 \twocolitem{{\bf wxBITMAP
\_TYPE\_XBM}}{Load an X bitmap file.
}
413 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Load an XPM bitmap file.
}
416 The validity of these flags depends on the platform and wxWindows configuration.
418 In addition, wxBitmap can read all formats that
\helpref{wxImage
}{wximage
} can
419 (wxBITMAP
\_TYPE\_JPEG, wxBITMAP
\_TYPE\_PNG, wxBITMAP
\_TYPE\_GIF, wxBITMAP
\_TYPE\_PCX, wxBITMAP
\_TYPE\_PNM).
420 (Of course you must have wxImage handlers loaded.)
}
422 \wxheading{Return value
}
424 TRUE if the operation succeeded, FALSE otherwise.
428 A palette may be associated with the bitmap if one exists (especially for
429 colour Windows bitmaps), and if the code supports it. You can check
430 if one has been created by using the
\helpref{GetPalette
}{wxbitmapgetpalette
} member.
434 \helpref{wxBitmap::SaveFile
}{wxbitmapsavefile
}
436 \membersection{wxBitmap::Ok
}\label{wxbitmapok
}
438 \constfunc{bool
}{Ok
}{\void}
440 Returns TRUE if bitmap data is present.
442 \membersection{wxBitmap::RemoveHandler
}
444 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
446 Finds the handler with the given name, and removes it. The handler
449 \docparam{name
}{The handler name.
}
451 \wxheading{Return value
}
453 TRUE if the handler was found and removed, FALSE otherwise.
457 \helpref{wxBitmapHandler
}{wxbitmaphandler
}
459 \membersection{wxBitmap::SaveFile
}\label{wxbitmapsavefile
}
461 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
},
\param{wxPalette*
}{palette = NULL
}}
463 Saves a bitmap in the named file.
465 \wxheading{Parameters
}
467 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
469 \docparam{type
}{One of the following values:
473 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Save a Windows bitmap file.
}
474 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Save a GIF bitmap file.
}
475 \twocolitem{{\bf wxBITMAP
\_TYPE\_XBM}}{Save an X bitmap file.
}
476 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Save an XPM bitmap file.
}
479 The validity of these flags depends on the platform and wxWindows configuration.
481 In addition, wxBitmap can save all formats that
\helpref{wxImage
}{wximage
} can
482 (wxBITMAP
\_TYPE\_JPEG, wxBITMAP
\_TYPE\_PNG).
483 (Of course you must have wxImage handlers loaded.)
}
485 \docparam{palette
}{An optional palette used for saving the bitmap.
}
486 % TODO: this parameter should
487 %probably be eliminated; instead the app should set the palette before saving.
489 \wxheading{Return value
}
491 TRUE if the operation succeeded, FALSE otherwise.
495 Depending on how wxWindows has been configured, not all formats may be available.
499 \helpref{wxBitmap::LoadFile
}{wxbitmaploadfile
}
501 \membersection{wxBitmap::SetDepth
}\label{wxbitmapsetdepth
}
503 \func{void
}{SetDepth
}{\param{int
}{depth
}}
505 Sets the depth member (does not affect the bitmap data).
507 \wxheading{Parameters
}
509 \docparam{depth
}{Bitmap depth.
}
511 \membersection{wxBitmap::SetHeight
}\label{wxbitmapsetheight
}
513 \func{void
}{SetHeight
}{\param{int
}{height
}}
515 Sets the height member (does not affect the bitmap data).
517 \wxheading{Parameters
}
519 \docparam{height
}{Bitmap height in pixels.
}
521 \membersection{wxBitmap::SetMask
}\label{wxbitmapsetmask
}
523 \func{void
}{SetMask
}{\param{wxMask*
}{mask
}}
525 Sets the mask for this bitmap.
529 The bitmap object owns the mask once this has been called.
533 \helpref{wxBitmap::GetMask
}{wxbitmapgetmask
},
\helpref{wxMask
}{wxmask
}
535 %% VZ: this function is an implementation detail and shouldn't be documented
536 %%\membersection{wxBitmap::SetOk}
538 %%\func{void}{SetOk}{\param{int }{isOk}}
540 %%Sets the validity member (does not affect the bitmap data).
542 %%\wxheading{Parameters}
544 %%\docparam{isOk}{Validity flag.}
546 \membersection{wxBitmap::SetPalette
}\label{wxbitmapsetpalette
}
548 \func{void
}{SetPalette
}{\param{const wxPalette\&
}{palette
}}
550 Sets the associated palette.
552 \wxheading{Parameters
}
554 \docparam{palette
}{The palette to set.
}
558 \helpref{wxPalette
}{wxpalette
}
560 \membersection{wxBitmap::SetWidth
}
562 \func{void
}{SetWidth
}{\param{int
}{width
}}
564 Sets the width member (does not affect the bitmap data).
566 \wxheading{Parameters
}
568 \docparam{width
}{Bitmap width in pixels.
}
570 \membersection{wxBitmap::operator $=$
}
572 \func{wxBitmap\&
}{operator $=$
}{\param{const wxBitmap\&
}{bitmap
}}
574 Assignment operator. This operator does not copy any data, but instead
575 passes a pointer to the data in
{\it bitmap
} and increments a reference
576 counter. It is a fast operation.
578 \wxheading{Parameters
}
580 \docparam{bitmap
}{Bitmap to assign.
}
582 \wxheading{Return value
}
584 Returns 'this' object.
586 \membersection{wxBitmap::operator $==$
}
588 \func{bool
}{operator $==$
}{\param{const wxBitmap\&
}{bitmap
}}
590 Equality operator. This operator tests whether the internal data pointers are
593 \wxheading{Parameters
}
595 \docparam{bitmap
}{Bitmap to compare with 'this'
}
597 \wxheading{Return value
}
599 Returns TRUE if the bitmaps were effectively equal, FALSE otherwise.
601 \membersection{wxBitmap::operator $!=$
}
603 \func{bool
}{operator $!=$
}{\param{const wxBitmap\&
}{bitmap
}}
605 Inequality operator. This operator tests whether the internal data pointers are
606 unequal (a fast test).
608 \wxheading{Parameters
}
610 \docparam{bitmap
}{Bitmap to compare with 'this'
}
612 \wxheading{Return value
}
614 Returns TRUE if the bitmaps were unequal, FALSE otherwise.