]>
git.saurik.com Git - wxWidgets.git/blob - interface/bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxBitmapHandler class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxBitmapHandler
15 This is the base class for implementing bitmap file loading/saving, and bitmap
17 It is used within wxBitmap and is not normally seen by the application.
19 If you wish to extend the capabilities of wxBitmap, derive a class from
21 and add the handler using wxBitmap::AddHandler in your
22 application initialisation.
28 wxBitmap, wxIcon, wxCursor
30 class wxBitmapHandler
: public wxObject
34 Default constructor. In your own default constructor, initialise the members
35 m_name, m_extension and m_type.
40 Destroys the wxBitmapHandler object.
45 Creates a bitmap from the given data, which can be of arbitrary type. The
46 wxBitmap object @e bitmap is
47 manipulated by this function.
53 The width of the bitmap in pixels.
56 The height of the bitmap in pixels.
59 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
62 Data whose type depends on the value of type.
65 A bitmap type identifier - see wxBitmapHandler() for a list
68 @returns @true if the call succeeded, @false otherwise (the default).
70 virtual bool Create(wxBitmap
* bitmap
, const void* data
, int type
,
76 Gets the file extension associated with this handler.
78 const wxString
GetExtension();
81 Gets the name of this handler.
83 const wxString
GetName();
86 Gets the bitmap type associated with this handler.
91 Loads a bitmap from a file or resource, putting the resulting data into @e
95 The bitmap object which is to be affected by this operation.
98 Either a filename or a Windows resource name.
99 The meaning of name is determined by the type parameter.
102 See wxBitmap::wxBitmap for values this can take.
104 @returns @true if the operation succeeded, @false otherwise.
106 @sa wxBitmap::LoadFile, wxBitmap::SaveFile, SaveFile()
108 bool LoadFile(wxBitmap
* bitmap
, const wxString
& name
, long type
);
111 Saves a bitmap in the named file.
114 The bitmap object which is to be affected by this operation.
117 A filename. The meaning of name is determined by the type parameter.
120 See wxBitmap::wxBitmap for values this can take.
123 An optional palette used for saving the bitmap.
125 @returns @true if the operation succeeded, @false otherwise.
127 @sa wxBitmap::LoadFile, wxBitmap::SaveFile, LoadFile()
129 bool SaveFile(wxBitmap
* bitmap
, const wxString
& name
, int type
,
130 wxPalette
* palette
= @NULL
);
133 Sets the handler extension.
138 void SetExtension(const wxString
& extension
);
141 Sets the handler name.
146 void SetName(const wxString
& name
);
149 Sets the handler type.
154 void SetType(long type
);
162 This class encapsulates the concept of a platform-dependent bitmap,
163 either monochrome or colour or colour with alpha channel support.
173 @ref overview_wxbitmapoverview "wxBitmap overview", @ref
174 overview_supportedbitmapformats "supported bitmap file formats", wxDC::Blit, wxIcon, wxCursor, wxBitmap, wxMemoryDC
176 class wxBitmap
: public wxGDIObject
181 Creates bitmap object from the image. This has to be done
182 to actually display an image as you cannot draw an image directly on a window.
183 The resulting bitmap will use the provided colour depth (or that of the
184 current system if depth is -1) which entails that a colour reduction has
187 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
189 on program start-up to look up colors. This ensures a very fast conversion, but
190 the image quality won't be perfect (and could be better for photo images using
192 sophisticated dithering algorithms).
194 On Windows, if there is a palette present (set with SetPalette), it will be
196 creating the wxBitmap (most useful in 8-bit display mode). On other platforms,
197 the palette is currently ignored.
200 Specifies an array of pixel values.
203 Specifies the width of the bitmap.
206 Specifies the height of the bitmap.
209 Specifies the depth of the bitmap. If this is omitted, the display depth of the
213 This can refer to a resource name under MS Windows, or a filename under MS
215 Its meaning is determined by the type parameter.
218 May be one of the following:
224 Load a Windows bitmap file.
226 wxBITMAP_TYPE_BMP_RESOURCE
229 Load a Windows bitmap resource from the executable. Windows only.
231 wxBITMAP_TYPE_PICT_RESOURCE
234 Load a PICT image resource from the executable. Mac OS only.
239 Load a GIF bitmap file.
244 Load an X bitmap file.
249 Load an XPM bitmap file.
251 The validity of these flags depends on the platform and wxWidgets configuration.
252 If all possible wxWidgets settings are used, the Windows platform supports BMP
254 XPM data, and XPM. Under wxGTK, the available formats are BMP file, XPM data,
255 XPM file, and PNG file.
256 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
258 In addition, wxBitmap can read all formats that wxImage can, which currently
260 wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_TIF, wxBITMAP_TYPE_PNG, wxBITMAP_TYPE_GIF,
262 and wxBITMAP_TYPE_PNM. Of course, you must have wxImage handlers loaded.
265 Platform-independent wxImage object.
267 @remarks The first form constructs a bitmap object with no data; an
268 assignment or another member function such as Create
269 or LoadFile must be called subsequently.
274 wxBitmap(const wxBitmap
& bitmap
);
275 wxBitmap(const void* data
, int type
, int width
, int height
,
277 wxBitmap(const char bits
[], int width
, int height
,
279 wxBitmap(int width
, int height
, int depth
= -1);
280 wxBitmap(const char* const* bits
);
281 wxBitmap(const wxString
& name
, long type
);
282 wxBitmap(const wxImage
& img
, int depth
= -1);
287 See @ref overview_refcountdestruct "reference-counted object destruction" for
290 If the application omits to delete the bitmap explicitly, the bitmap will be
291 destroyed automatically by wxWidgets when the application exits.
293 Do not delete a bitmap that is selected into a memory device context.
298 Adds a handler to the end of the static list of format handlers.
301 A new bitmap format handler object. There is usually only one instance
302 of a given handler class in an application session.
306 static void AddHandler(wxBitmapHandler
* handler
);
309 Deletes all bitmap handlers.
311 This function is called by wxWidgets on exit.
313 static void CleanUpHandlers();
316 Creates an image from a platform-dependent bitmap. This preserves
317 mask information so that bitmaps and images can be converted back
318 and forth without loss in that respect.
320 wxImage
ConvertToImage();
323 Creates the bitmap from an icon.
325 bool CopyFromIcon(const wxIcon
& icon
);
329 Creates a bitmap from the given data, which can be of arbitrary type.
332 The width of the bitmap in pixels.
335 The height of the bitmap in pixels.
338 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
341 Data whose type depends on the value of type.
344 A bitmap type identifier - see wxBitmap() for a list
347 @returns @true if the call succeeded, @false otherwise.
349 @remarks The first form works on all platforms. The portability of the
350 second form depends on the type of data.
354 virtual bool Create(int width
, int height
, int depth
= -1);
355 virtual bool Create(const void* data
, int type
, int width
,
362 Finds the handler associated with the given bitmap type.
368 The file extension, such as "bmp".
371 The bitmap type, such as wxBITMAP_TYPE_BMP.
373 @returns A pointer to the handler if found, @NULL otherwise.
377 static wxBitmapHandler
* FindHandler(const wxString
& name
);
378 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
379 wxBitmapType bitmapType
);
380 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
384 Gets the colour depth of the bitmap. A value of 1 indicates a
390 Returns the static list of bitmap format handlers.
394 static wxList
GetHandlers();
397 Gets the height of the bitmap in pixels.
402 Gets the associated mask (if any) which may have been loaded from a file
403 or set for the bitmap.
405 @sa SetMask(), wxMask
410 Gets the associated palette (if any) which may have been loaded from a file
411 or set for the bitmap.
415 wxPalette
* GetPalette();
418 Returns a sub bitmap of the current one as long as the rect belongs entirely to
419 the bitmap. This function preserves bit depth and mask information.
421 wxBitmap
GetSubBitmap(const wxRect
& rect
);
424 Gets the width of the bitmap in pixels.
431 Adds the standard bitmap format handlers, which, depending on wxWidgets
432 configuration, can be handlers for Windows bitmap, Windows bitmap resource, and
435 This function is called by wxWidgets on startup.
439 static void InitStandardHandlers();
442 Adds a handler at the start of the static list of format handlers.
445 A new bitmap format handler object. There is usually only one instance
446 of a given handler class in an application session.
450 static void InsertHandler(wxBitmapHandler
* handler
);
453 Returns @true if bitmap data is present.
455 #define bool IsOk() /* implementation is private */
458 Loads a bitmap from a file or resource.
461 Either a filename or a Windows resource name.
462 The meaning of name is determined by the type parameter.
465 One of the following values:
471 Load a Windows bitmap file.
473 wxBITMAP_TYPE_BMP_RESOURCE
476 Load a Windows bitmap resource from the executable.
478 wxBITMAP_TYPE_PICT_RESOURCE
481 Load a PICT image resource from the executable. Mac OS only.
486 Load a GIF bitmap file.
491 Load an X bitmap file.
496 Load an XPM bitmap file.
498 The validity of these flags depends on the platform and wxWidgets configuration.
500 In addition, wxBitmap can read all formats that wxImage can
501 (wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG, wxBITMAP_TYPE_GIF, wxBITMAP_TYPE_PCX,
503 (Of course you must have wxImage handlers loaded.)
505 @returns @true if the operation succeeded, @false otherwise.
507 @remarks A palette may be associated with the bitmap if one exists
508 (especially for colour Windows bitmaps), and if the
509 code supports it. You can check if one has been
510 created by using the GetPalette member.
514 bool LoadFile(const wxString
& name
, wxBitmapType type
);
517 Finds the handler with the given name, and removes it. The handler
523 @returns @true if the handler was found and removed, @false otherwise.
527 static bool RemoveHandler(const wxString
& name
);
530 Saves a bitmap in the named file.
533 A filename. The meaning of name is determined by the type parameter.
536 One of the following values:
542 Save a Windows bitmap file.
547 Save a GIF bitmap file.
552 Save an X bitmap file.
557 Save an XPM bitmap file.
559 The validity of these flags depends on the platform and wxWidgets configuration.
561 In addition, wxBitmap can save all formats that wxImage can
562 (wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG).
563 (Of course you must have wxImage handlers loaded.)
566 An optional palette used for saving the bitmap.
568 @returns @true if the operation succeeded, @false otherwise.
570 @remarks Depending on how wxWidgets has been configured, not all formats
575 bool SaveFile(const wxString
& name
, wxBitmapType type
,
576 wxPalette
* palette
= @NULL
);
579 Sets the depth member (does not affect the bitmap data).
584 void SetDepth(int depth
);
587 Sets the height member (does not affect the bitmap data).
590 Bitmap height in pixels.
592 void SetHeight(int height
);
595 Sets the mask for this bitmap.
597 @remarks The bitmap object owns the mask once this has been called.
599 @sa GetMask(), wxMask
601 void SetMask(wxMask
* mask
);
604 Sets the associated palette. (Not implemented under GTK+).
611 void SetPalette(const wxPalette
& palette
);
614 Sets the width member (does not affect the bitmap data).
617 Bitmap width in pixels.
619 void SetWidth(int width
);
622 Assignment operator, using @ref overview_trefcount "reference counting".
627 wxBitmap
operator =(const wxBitmap
& bitmap
);
635 This class encapsulates a monochrome mask bitmap, where the masked area is
637 the unmasked area is white. When associated with a bitmap and drawn in a device
639 the unmasked area of the bitmap will be drawn, and the masked area will not be
646 wxBitmap, wxDC::Blit, wxMemoryDC
648 class wxMask
: public wxObject
653 Constructs a mask from a bitmap and a palette index that indicates the
655 yet implemented for GTK.
661 A colour specifying the transparency RGB values.
664 Index into a palette, specifying the transparency colour.
667 wxMask(const wxBitmap
& bitmap
);
668 wxMask(const wxBitmap
& bitmap
,
669 const wxColour
& colour
);
670 wxMask(const wxBitmap
& bitmap
, int index
);
674 Destroys the wxMask object and the underlying bitmap data.
680 Constructs a mask from a bitmap and a palette index that indicates the
682 yet implemented for GTK.
688 A colour specifying the transparency RGB values.
691 Index into a palette, specifying the transparency colour.
693 bool Create(const wxBitmap
& bitmap
);
694 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
695 bool Create(const wxBitmap
& bitmap
, int index
);