]>
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
);
152 This class encapsulates the concept of a platform-dependent bitmap,
153 either monochrome or colour or colour with alpha channel support.
159 ::Objects:, ::wxNullBitmap,
161 @see @ref overview_wxbitmapoverview "wxBitmap overview", @ref
162 overview_supportedbitmapformats "supported bitmap file formats", wxDC::Blit, wxIcon, wxCursor, wxBitmap, wxMemoryDC
164 class wxBitmap
: public wxGDIObject
169 Creates bitmap object from the image. This has to be done
170 to actually display an image as you cannot draw an image directly on a window.
171 The resulting bitmap will use the provided colour depth (or that of the
172 current system if depth is -1) which entails that a colour reduction has
174 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
176 on program start-up to look up colors. This ensures a very fast conversion, but
177 the image quality won't be perfect (and could be better for photo images using
179 sophisticated dithering algorithms).
180 On Windows, if there is a palette present (set with SetPalette), it will be
182 creating the wxBitmap (most useful in 8-bit display mode). On other platforms,
183 the palette is currently ignored.
186 Specifies an array of pixel values.
188 Specifies the width of the bitmap.
190 Specifies the height of the bitmap.
192 Specifies the depth of the bitmap. If this is omitted, the display depth of
196 This can refer to a resource name under MS Windows, or a filename under MS
198 Its meaning is determined by the type parameter.
200 May be one of the following:
213 Load a Windows bitmap file.
219 wxBITMAP_TYPE_BMP_RESOURCE
224 Load a Windows bitmap resource from the executable. Windows only.
230 wxBITMAP_TYPE_PICT_RESOURCE
235 Load a PICT image resource from the executable. Mac OS only.
246 Load a GIF bitmap file.
257 Load an X bitmap file.
268 Load an XPM bitmap file.
274 The validity of these flags depends on the platform and wxWidgets
276 If all possible wxWidgets settings are used, the Windows platform supports
277 BMP file, BMP resource,
278 XPM data, and XPM. Under wxGTK, the available formats are BMP file, XPM
279 data, XPM file, and PNG file.
280 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM
282 In addition, wxBitmap can read all formats that wxImage can, which
284 wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_TIF, wxBITMAP_TYPE_PNG,
285 wxBITMAP_TYPE_GIF, wxBITMAP_TYPE_PCX,
286 and wxBITMAP_TYPE_PNM. Of course, you must have wxImage handlers loaded.
288 Platform-independent wxImage object.
290 @remarks The first form constructs a bitmap object with no data; an
291 assignment or another member function such as Create or
292 LoadFile must be called subsequently.
297 wxBitmap(const wxBitmap
& bitmap
);
298 wxBitmap(const void* data
, int type
, int width
, int height
,
300 wxBitmap(const char bits
[], int width
, int height
,
302 wxBitmap(int width
, int height
, int depth
= -1);
303 wxBitmap(const char* const* bits
);
304 wxBitmap(const wxString
& name
, long type
);
305 wxBitmap(const wxImage
& img
, int depth
= -1);
310 See @ref overview_refcountdestruct "reference-counted object destruction" for
312 If the application omits to delete the bitmap explicitly, the bitmap will be
313 destroyed automatically by wxWidgets when the application exits.
314 Do not delete a bitmap that is selected into a memory device context.
319 Adds a handler to the end of the static list of format handlers.
322 A new bitmap format handler object. There is usually only one instance
323 of a given handler class in an application session.
327 static void AddHandler(wxBitmapHandler
* handler
);
330 Deletes all bitmap handlers.
331 This function is called by wxWidgets on exit.
333 static void CleanUpHandlers();
336 Creates an image from a platform-dependent bitmap. This preserves
337 mask information so that bitmaps and images can be converted back
338 and forth without loss in that respect.
340 wxImage
ConvertToImage();
343 Creates the bitmap from an icon.
345 bool CopyFromIcon(const wxIcon
& icon
);
349 Creates a bitmap from the given data, which can be of arbitrary type.
352 The width of the bitmap in pixels.
354 The height of the bitmap in pixels.
356 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
358 Data whose type depends on the value of type.
360 A bitmap type identifier - see wxBitmap() for a list
363 @returns @true if the call succeeded, @false otherwise.
365 @remarks The first form works on all platforms. The portability of the
366 second form depends on the type of data.
370 virtual bool Create(int width
, int height
, int depth
= -1);
371 virtual bool Create(const void* data
, int type
, int width
,
378 Finds the handler associated with the given bitmap type.
383 The file extension, such as "bmp".
385 The bitmap type, such as wxBITMAP_TYPE_BMP.
387 @returns A pointer to the handler if found, @NULL otherwise.
391 static wxBitmapHandler
* FindHandler(const wxString
& name
);
392 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
393 wxBitmapType bitmapType
);
394 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
398 Gets the colour depth of the bitmap. A value of 1 indicates a
401 int GetDepth() const;
404 Returns the static list of bitmap format handlers.
408 static wxList
GetHandlers();
411 Gets the height of the bitmap in pixels.
413 int GetHeight() const;
416 Gets the associated mask (if any) which may have been loaded from a file
417 or set for the bitmap.
419 @see SetMask(), wxMask
421 wxMask
* GetMask() const;
424 Gets the associated palette (if any) which may have been loaded from a file
425 or set for the bitmap.
429 wxPalette
* GetPalette() const;
432 Returns a sub bitmap of the current one as long as the rect belongs entirely to
433 the bitmap. This function preserves bit depth and mask information.
435 wxBitmap
GetSubBitmap(const wxRect
& rect
) const;
438 Gets the width of the bitmap in pixels.
442 int GetWidth() const;
445 Adds the standard bitmap format handlers, which, depending on wxWidgets
446 configuration, can be handlers for Windows bitmap, Windows bitmap resource, and
448 This function is called by wxWidgets on startup.
452 static void InitStandardHandlers();
455 Adds a handler at the start of the static list of format handlers.
458 A new bitmap format handler object. There is usually only one instance
459 of a given handler class in an application session.
463 static void InsertHandler(wxBitmapHandler
* handler
);
466 Returns @true if bitmap data is present.
471 Loads a bitmap from a file or resource.
474 Either a filename or a Windows resource name.
475 The meaning of name is determined by the type parameter.
477 One of the following values:
490 Load a Windows bitmap file.
496 wxBITMAP_TYPE_BMP_RESOURCE
501 Load a Windows bitmap resource from the executable.
507 wxBITMAP_TYPE_PICT_RESOURCE
512 Load a PICT image resource from the executable. Mac OS only.
523 Load a GIF bitmap file.
534 Load an X bitmap file.
545 Load an XPM bitmap file.
551 The validity of these flags depends on the platform and wxWidgets
553 In addition, wxBitmap can read all formats that wxImage can
554 (wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG, wxBITMAP_TYPE_GIF,
555 wxBITMAP_TYPE_PCX, wxBITMAP_TYPE_PNM).
556 (Of course you must have wxImage handlers loaded.)
558 @returns @true if the operation succeeded, @false otherwise.
560 @remarks A palette may be associated with the bitmap if one exists
561 (especially for colour Windows bitmaps), and if the
562 code supports it. You can check if one has been created
563 by using the GetPalette member.
567 bool LoadFile(const wxString
& name
, wxBitmapType type
);
570 Finds the handler with the given name, and removes it. The handler
576 @returns @true if the handler was found and removed, @false otherwise.
580 static bool RemoveHandler(const wxString
& name
);
583 Saves a bitmap in the named file.
586 A filename. The meaning of name is determined by the type parameter.
588 One of the following values:
601 Save a Windows bitmap file.
612 Save a GIF bitmap file.
623 Save an X bitmap file.
634 Save an XPM bitmap file.
640 The validity of these flags depends on the platform and wxWidgets
642 In addition, wxBitmap can save all formats that wxImage can
643 (wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG).
644 (Of course you must have wxImage handlers loaded.)
646 An optional palette used for saving the bitmap.
648 @returns @true if the operation succeeded, @false otherwise.
650 @remarks Depending on how wxWidgets has been configured, not all formats
655 bool SaveFile(const wxString
& name
, wxBitmapType type
,
656 wxPalette
* palette
= NULL
);
659 Sets the depth member (does not affect the bitmap data).
664 void SetDepth(int depth
);
667 Sets the height member (does not affect the bitmap data).
670 Bitmap height in pixels.
672 void SetHeight(int height
);
675 Sets the mask for this bitmap.
677 @remarks The bitmap object owns the mask once this has been called.
679 @see GetMask(), wxMask
681 void SetMask(wxMask
* mask
);
684 Sets the associated palette. (Not implemented under GTK+).
691 void SetPalette(const wxPalette
& palette
);
694 Sets the width member (does not affect the bitmap data).
697 Bitmap width in pixels.
699 void SetWidth(int width
);
702 Assignment operator, using @ref overview_trefcount "reference counting".
707 wxBitmap
operator =(const wxBitmap
& bitmap
);
720 wxBitmap wxNullBitmap
;
729 This class encapsulates a monochrome mask bitmap, where the masked area is
731 the unmasked area is white. When associated with a bitmap and drawn in a device
733 the unmasked area of the bitmap will be drawn, and the masked area will not be
739 @see wxBitmap, wxDC::Blit, wxMemoryDC
741 class wxMask
: public wxObject
746 Constructs a mask from a bitmap and a palette index that indicates the
748 yet implemented for GTK.
753 A colour specifying the transparency RGB values.
755 Index into a palette, specifying the transparency colour.
758 wxMask(const wxBitmap
& bitmap
);
759 wxMask(const wxBitmap
& bitmap
,
760 const wxColour
& colour
);
761 wxMask(const wxBitmap
& bitmap
, int index
);
765 Destroys the wxMask object and the underlying bitmap data.
771 Constructs a mask from a bitmap and a palette index that indicates the
773 yet implemented for GTK.
778 A colour specifying the transparency RGB values.
780 Index into a palette, specifying the transparency colour.
782 bool Create(const wxBitmap
& bitmap
);
783 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
784 bool Create(const wxBitmap
& bitmap
, int index
);