]>
git.saurik.com Git - wxWidgets.git/blob - interface/bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxBitmapHandler
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.
27 @see wxBitmap, wxIcon, wxCursor
29 class wxBitmapHandler
: public wxObject
33 Default constructor. In your own default constructor, initialise the members
34 m_name, m_extension and m_type.
39 Destroys the wxBitmapHandler object.
44 Creates a bitmap from the given data, which can be of arbitrary type. The
45 wxBitmap object @a bitmap is
46 manipulated by this function.
51 The width of the bitmap in pixels.
53 The height of the bitmap in pixels.
55 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
57 Data whose type depends on the value of type.
59 A bitmap type identifier - see wxBitmapHandler() for a list
62 @returns @true if the call succeeded, @false otherwise (the default).
64 virtual bool Create(wxBitmap
* bitmap
, const void* data
, int type
,
70 Gets the file extension associated with this handler.
72 const wxString
GetExtension() const;
75 Gets the name of this handler.
77 const wxString
GetName() const;
80 Gets the bitmap type associated with this handler.
85 Loads a bitmap from a file or resource, putting the resulting data into @e
89 The bitmap object which is to be affected by this operation.
91 Either a filename or a Windows resource name.
92 The meaning of name is determined by the type parameter.
94 See wxBitmap::wxBitmap for values this can take.
96 @returns @true if the operation succeeded, @false otherwise.
98 @see wxBitmap::LoadFile, wxBitmap::SaveFile, SaveFile()
100 bool LoadFile(wxBitmap
* bitmap
, const wxString
& name
, long type
);
103 Saves a bitmap in the named file.
106 The bitmap object which is to be affected by this operation.
108 A filename. The meaning of name is determined by the type parameter.
110 See wxBitmap::wxBitmap for values this can take.
112 An optional palette used for saving the bitmap.
114 @returns @true if the operation succeeded, @false otherwise.
116 @see wxBitmap::LoadFile, wxBitmap::SaveFile, LoadFile()
118 bool SaveFile(wxBitmap
* bitmap
, const wxString
& name
, int type
,
119 wxPalette
* palette
= NULL
);
122 Sets the handler extension.
127 void SetExtension(const wxString
& extension
);
130 Sets the handler name.
135 void SetName(const wxString
& name
);
138 Sets the handler type.
143 void SetType(long type
);
150 @ingroup group_class_gdi
153 This class encapsulates the concept of a platform-dependent bitmap,
154 either monochrome or colour or colour with alpha channel support.
160 ::Objects:, ::wxNullBitmap,
162 @see @ref overview_wxbitmapoverview "wxBitmap overview", @ref
163 overview_supportedbitmapformats "supported bitmap file formats", wxDC::Blit, wxIcon, wxCursor, wxBitmap, wxMemoryDC
165 class wxBitmap
: public wxGDIObject
170 Creates bitmap object from the image. This has to be done
171 to actually display an image as you cannot draw an image directly on a window.
172 The resulting bitmap will use the provided colour depth (or that of the
173 current system if depth is -1) which entails that a colour reduction has
175 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
177 on program start-up to look up colors. This ensures a very fast conversion, but
178 the image quality won't be perfect (and could be better for photo images using
180 sophisticated dithering algorithms).
181 On Windows, if there is a palette present (set with SetPalette), it will be
183 creating the wxBitmap (most useful in 8-bit display mode). On other platforms,
184 the palette is currently ignored.
187 Specifies an array of pixel values.
189 Specifies the width of the bitmap.
191 Specifies the height of the bitmap.
193 Specifies the depth of the bitmap. If this is omitted, the display depth of
197 This can refer to a resource name under MS Windows, or a filename under MS
199 Its meaning is determined by the type parameter.
201 May be one of the following:
214 Load a Windows bitmap file.
220 wxBITMAP_TYPE_BMP_RESOURCE
225 Load a Windows bitmap resource from the executable. Windows only.
231 wxBITMAP_TYPE_PICT_RESOURCE
236 Load a PICT image resource from the executable. Mac OS only.
247 Load a GIF bitmap file.
258 Load an X bitmap file.
269 Load an XPM bitmap file.
275 The validity of these flags depends on the platform and wxWidgets
277 If all possible wxWidgets settings are used, the Windows platform supports
278 BMP file, BMP resource,
279 XPM data, and XPM. Under wxGTK, the available formats are BMP file, XPM
280 data, XPM file, and PNG file.
281 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM
283 In addition, wxBitmap can read all formats that wxImage can, which
285 wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_TIF, wxBITMAP_TYPE_PNG,
286 wxBITMAP_TYPE_GIF, wxBITMAP_TYPE_PCX,
287 and wxBITMAP_TYPE_PNM. Of course, you must have wxImage handlers loaded.
289 Platform-independent wxImage object.
291 @remarks The first form constructs a bitmap object with no data; an
292 assignment or another member function such as Create or
293 LoadFile must be called subsequently.
298 wxBitmap(const wxBitmap
& bitmap
);
299 wxBitmap(const void* data
, int type
, int width
, int height
,
301 wxBitmap(const char bits
[], int width
, int height
,
303 wxBitmap(int width
, int height
, int depth
= -1);
304 wxBitmap(const char* const* bits
);
305 wxBitmap(const wxString
& name
, long type
);
306 wxBitmap(const wxImage
& img
, int depth
= -1);
311 See @ref overview_refcountdestruct "reference-counted object destruction" for
313 If the application omits to delete the bitmap explicitly, the bitmap will be
314 destroyed automatically by wxWidgets when the application exits.
315 Do not delete a bitmap that is selected into a memory device context.
320 Adds a handler to the end of the static list of format handlers.
323 A new bitmap format handler object. There is usually only one instance
324 of a given handler class in an application session.
328 static void AddHandler(wxBitmapHandler
* handler
);
331 Deletes all bitmap handlers.
332 This function is called by wxWidgets on exit.
334 static void CleanUpHandlers();
337 Creates an image from a platform-dependent bitmap. This preserves
338 mask information so that bitmaps and images can be converted back
339 and forth without loss in that respect.
341 wxImage
ConvertToImage();
344 Creates the bitmap from an icon.
346 bool CopyFromIcon(const wxIcon
& icon
);
350 Creates a bitmap from the given data, which can be of arbitrary type.
353 The width of the bitmap in pixels.
355 The height of the bitmap in pixels.
357 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
359 Data whose type depends on the value of type.
361 A bitmap type identifier - see wxBitmap() for a list
364 @returns @true if the call succeeded, @false otherwise.
366 @remarks The first form works on all platforms. The portability of the
367 second form depends on the type of data.
371 virtual bool Create(int width
, int height
, int depth
= -1);
372 virtual bool Create(const void* data
, int type
, int width
,
379 Finds the handler associated with the given bitmap type.
384 The file extension, such as "bmp".
386 The bitmap type, such as wxBITMAP_TYPE_BMP.
388 @returns A pointer to the handler if found, @NULL otherwise.
392 static wxBitmapHandler
* FindHandler(const wxString
& name
);
393 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
394 wxBitmapType bitmapType
);
395 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
399 Gets the colour depth of the bitmap. A value of 1 indicates a
402 int GetDepth() const;
405 Returns the static list of bitmap format handlers.
409 static wxList
GetHandlers();
412 Gets the height of the bitmap in pixels.
414 int GetHeight() const;
417 Gets the associated mask (if any) which may have been loaded from a file
418 or set for the bitmap.
420 @see SetMask(), wxMask
422 wxMask
* GetMask() const;
425 Gets the associated palette (if any) which may have been loaded from a file
426 or set for the bitmap.
430 wxPalette
* GetPalette() const;
433 Returns a sub bitmap of the current one as long as the rect belongs entirely to
434 the bitmap. This function preserves bit depth and mask information.
436 wxBitmap
GetSubBitmap(const wxRect
& rect
) const;
439 Gets the width of the bitmap in pixels.
443 int GetWidth() const;
446 Adds the standard bitmap format handlers, which, depending on wxWidgets
447 configuration, can be handlers for Windows bitmap, Windows bitmap resource, and
449 This function is called by wxWidgets on startup.
453 static void InitStandardHandlers();
456 Adds a handler at the start of the static list of format handlers.
459 A new bitmap format handler object. There is usually only one instance
460 of a given handler class in an application session.
464 static void InsertHandler(wxBitmapHandler
* handler
);
467 Returns @true if bitmap data is present.
472 Loads a bitmap from a file or resource.
475 Either a filename or a Windows resource name.
476 The meaning of name is determined by the type parameter.
478 One of the following values:
491 Load a Windows bitmap file.
497 wxBITMAP_TYPE_BMP_RESOURCE
502 Load a Windows bitmap resource from the executable.
508 wxBITMAP_TYPE_PICT_RESOURCE
513 Load a PICT image resource from the executable. Mac OS only.
524 Load a GIF bitmap file.
535 Load an X bitmap file.
546 Load an XPM bitmap file.
552 The validity of these flags depends on the platform and wxWidgets
554 In addition, wxBitmap can read all formats that wxImage can
555 (wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG, wxBITMAP_TYPE_GIF,
556 wxBITMAP_TYPE_PCX, wxBITMAP_TYPE_PNM).
557 (Of course you must have wxImage handlers loaded.)
559 @returns @true if the operation succeeded, @false otherwise.
561 @remarks A palette may be associated with the bitmap if one exists
562 (especially for colour Windows bitmaps), and if the
563 code supports it. You can check if one has been created
564 by using the GetPalette member.
568 bool LoadFile(const wxString
& name
, wxBitmapType type
);
571 Finds the handler with the given name, and removes it. The handler
577 @returns @true if the handler was found and removed, @false otherwise.
581 static bool RemoveHandler(const wxString
& name
);
584 Saves a bitmap in the named file.
587 A filename. The meaning of name is determined by the type parameter.
589 One of the following values:
602 Save a Windows bitmap file.
613 Save a GIF bitmap file.
624 Save an X bitmap file.
635 Save an XPM bitmap file.
641 The validity of these flags depends on the platform and wxWidgets
643 In addition, wxBitmap can save all formats that wxImage can
644 (wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG).
645 (Of course you must have wxImage handlers loaded.)
647 An optional palette used for saving the bitmap.
649 @returns @true if the operation succeeded, @false otherwise.
651 @remarks Depending on how wxWidgets has been configured, not all formats
656 bool SaveFile(const wxString
& name
, wxBitmapType type
,
657 wxPalette
* palette
= NULL
);
660 Sets the depth member (does not affect the bitmap data).
665 void SetDepth(int depth
);
668 Sets the height member (does not affect the bitmap data).
671 Bitmap height in pixels.
673 void SetHeight(int height
);
676 Sets the mask for this bitmap.
678 @remarks The bitmap object owns the mask once this has been called.
680 @see GetMask(), wxMask
682 void SetMask(wxMask
* mask
);
685 Sets the associated palette. (Not implemented under GTK+).
692 void SetPalette(const wxPalette
& palette
);
695 Sets the width member (does not affect the bitmap data).
698 Bitmap width in pixels.
700 void SetWidth(int width
);
703 Assignment operator, using @ref overview_trefcount "reference counting".
708 wxBitmap
operator =(const wxBitmap
& bitmap
);
721 wxBitmap wxNullBitmap
;
728 @ingroup group_class_gdi
731 This class encapsulates a monochrome mask bitmap, where the masked area is
733 the unmasked area is white. When associated with a bitmap and drawn in a device
735 the unmasked area of the bitmap will be drawn, and the masked area will not be
741 @see wxBitmap, wxDC::Blit, wxMemoryDC
743 class wxMask
: public wxObject
748 Constructs a mask from a bitmap and a palette index that indicates the
750 yet implemented for GTK.
755 A colour specifying the transparency RGB values.
757 Index into a palette, specifying the transparency colour.
760 wxMask(const wxBitmap
& bitmap
);
761 wxMask(const wxBitmap
& bitmap
,
762 const wxColour
& colour
);
763 wxMask(const wxBitmap
& bitmap
, int index
);
767 Destroys the wxMask object and the underlying bitmap data.
773 Constructs a mask from a bitmap and a palette index that indicates the
775 yet implemented for GTK.
780 A colour specifying the transparency RGB values.
782 Index into a palette, specifying the transparency colour.
784 bool Create(const wxBitmap
& bitmap
);
785 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
786 bool Create(const wxBitmap
& bitmap
, int index
);