]>
git.saurik.com Git - wxWidgets.git/blob - interface/bitmap.h
a8aff7efe0d53d0112b88fb0f5cf2bbc8585edc2
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 @a bitmap is
47 manipulated by this function.
52 The width of the bitmap in pixels.
54 The height of the bitmap in pixels.
56 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
58 Data whose type depends on the value of type.
60 A bitmap type identifier - see wxBitmapHandler() for a list
63 @returns @true if the call succeeded, @false otherwise (the default).
65 virtual bool Create(wxBitmap
* bitmap
, const void* data
, int type
,
71 Gets the file extension associated with this handler.
73 const wxString
GetExtension();
76 Gets the name of this handler.
78 const wxString
GetName();
81 Gets the bitmap type associated with this handler.
86 Loads a bitmap from a file or resource, putting the resulting data into @e
90 The bitmap object which is to be affected by this operation.
92 Either a filename or a Windows resource name.
93 The meaning of name is determined by the type parameter.
95 See wxBitmap::wxBitmap for values this can take.
97 @returns @true if the operation succeeded, @false otherwise.
99 @see wxBitmap::LoadFile, wxBitmap::SaveFile, SaveFile()
101 bool LoadFile(wxBitmap
* bitmap
, const wxString
& name
, long type
);
104 Saves a bitmap in the named file.
107 The bitmap object which is to be affected by this operation.
109 A filename. The meaning of name is determined by the type parameter.
111 See wxBitmap::wxBitmap for values this can take.
113 An optional palette used for saving the bitmap.
115 @returns @true if the operation succeeded, @false otherwise.
117 @see wxBitmap::LoadFile, wxBitmap::SaveFile, LoadFile()
119 bool SaveFile(wxBitmap
* bitmap
, const wxString
& name
, int type
,
120 wxPalette
* palette
= NULL
);
123 Sets the handler extension.
128 void SetExtension(const wxString
& extension
);
131 Sets the handler name.
136 void SetName(const wxString
& name
);
139 Sets the handler type.
144 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.
163 @ref overview_wxbitmapoverview "wxBitmap overview", @ref
164 overview_supportedbitmapformats "supported bitmap file formats", wxDC::Blit, wxIcon, wxCursor, wxBitmap, wxMemoryDC
166 class wxBitmap
: public wxGDIObject
171 Creates bitmap object from the image. This has to be done
172 to actually display an image as you cannot draw an image directly on a window.
173 The resulting bitmap will use the provided colour depth (or that of the
174 current system if depth is -1) which entails that a colour reduction has
176 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
178 on program start-up to look up colors. This ensures a very fast conversion, but
179 the image quality won't be perfect (and could be better for photo images using
181 sophisticated dithering algorithms).
182 On Windows, if there is a palette present (set with SetPalette), it will be
184 creating the wxBitmap (most useful in 8-bit display mode). On other platforms,
185 the palette is currently ignored.
188 Specifies an array of pixel values.
190 Specifies the width of the bitmap.
192 Specifies the height of the bitmap.
194 Specifies the depth of the bitmap. If this is omitted, the display depth of
198 This can refer to a resource name under MS Windows, or a filename under MS
200 Its meaning is determined by the type parameter.
202 May be one of the following:
215 Load a Windows bitmap file.
221 wxBITMAP_TYPE_BMP_RESOURCE
226 Load a Windows bitmap resource from the executable. Windows only.
232 wxBITMAP_TYPE_PICT_RESOURCE
237 Load a PICT image resource from the executable. Mac OS only.
248 Load a GIF bitmap file.
259 Load an X bitmap file.
270 Load an XPM bitmap file.
276 The validity of these flags depends on the platform and wxWidgets
278 If all possible wxWidgets settings are used, the Windows platform supports
279 BMP file, BMP resource,
280 XPM data, and XPM. Under wxGTK, the available formats are BMP file, XPM
281 data, XPM file, and PNG file.
282 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM
284 In addition, wxBitmap can read all formats that wxImage can, which
286 wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_TIF, wxBITMAP_TYPE_PNG,
287 wxBITMAP_TYPE_GIF, wxBITMAP_TYPE_PCX,
288 and wxBITMAP_TYPE_PNM. Of course, you must have wxImage handlers loaded.
290 Platform-independent wxImage object.
292 @remarks The first form constructs a bitmap object with no data; an
293 assignment or another member function such as Create or
294 LoadFile must be called subsequently.
299 wxBitmap(const wxBitmap
& bitmap
);
300 wxBitmap(const void* data
, int type
, int width
, int height
,
302 wxBitmap(const char bits
[], int width
, int height
,
304 wxBitmap(int width
, int height
, int depth
= -1);
305 wxBitmap(const char* const* bits
);
306 wxBitmap(const wxString
& name
, long type
);
307 wxBitmap(const wxImage
& img
, int depth
= -1);
312 See @ref overview_refcountdestruct "reference-counted object destruction" for
314 If the application omits to delete the bitmap explicitly, the bitmap will be
315 destroyed automatically by wxWidgets when the application exits.
316 Do not delete a bitmap that is selected into a memory device context.
321 Adds a handler to the end of the static list of format handlers.
324 A new bitmap format handler object. There is usually only one instance
325 of a given handler class in an application session.
329 static void AddHandler(wxBitmapHandler
* handler
);
332 Deletes all bitmap handlers.
333 This function is called by wxWidgets on exit.
335 static void CleanUpHandlers();
338 Creates an image from a platform-dependent bitmap. This preserves
339 mask information so that bitmaps and images can be converted back
340 and forth without loss in that respect.
342 wxImage
ConvertToImage();
345 Creates the bitmap from an icon.
347 bool CopyFromIcon(const wxIcon
& icon
);
351 Creates a bitmap from the given data, which can be of arbitrary type.
354 The width of the bitmap in pixels.
356 The height of the bitmap in pixels.
358 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
360 Data whose type depends on the value of type.
362 A bitmap type identifier - see wxBitmap() for a list
365 @returns @true if the call succeeded, @false otherwise.
367 @remarks The first form works on all platforms. The portability of the
368 second form depends on the type of data.
372 virtual bool Create(int width
, int height
, int depth
= -1);
373 virtual bool Create(const void* data
, int type
, int width
,
380 Finds the handler associated with the given bitmap type.
385 The file extension, such as "bmp".
387 The bitmap type, such as wxBITMAP_TYPE_BMP.
389 @returns A pointer to the handler if found, @NULL otherwise.
393 static wxBitmapHandler
* FindHandler(const wxString
& name
);
394 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
395 wxBitmapType bitmapType
);
396 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
400 Gets the colour depth of the bitmap. A value of 1 indicates a
406 Returns the static list of bitmap format handlers.
410 static wxList
GetHandlers();
413 Gets the height of the bitmap in pixels.
418 Gets the associated mask (if any) which may have been loaded from a file
419 or set for the bitmap.
421 @see SetMask(), wxMask
426 Gets the associated palette (if any) which may have been loaded from a file
427 or set for the bitmap.
431 wxPalette
* GetPalette();
434 Returns a sub bitmap of the current one as long as the rect belongs entirely to
435 the bitmap. This function preserves bit depth and mask information.
437 wxBitmap
GetSubBitmap(const wxRect
& rect
);
440 Gets the width of the bitmap in pixels.
447 Adds the standard bitmap format handlers, which, depending on wxWidgets
448 configuration, can be handlers for Windows bitmap, Windows bitmap resource, and
450 This function is called by wxWidgets on startup.
454 static void InitStandardHandlers();
457 Adds a handler at the start of the static list of format handlers.
460 A new bitmap format handler object. There is usually only one instance
461 of a given handler class in an application session.
465 static void InsertHandler(wxBitmapHandler
* handler
);
468 Returns @true if bitmap data is present.
473 Loads a bitmap from a file or resource.
476 Either a filename or a Windows resource name.
477 The meaning of name is determined by the type parameter.
479 One of the following values:
492 Load a Windows bitmap file.
498 wxBITMAP_TYPE_BMP_RESOURCE
503 Load a Windows bitmap resource from the executable.
509 wxBITMAP_TYPE_PICT_RESOURCE
514 Load a PICT image resource from the executable. Mac OS only.
525 Load a GIF bitmap file.
536 Load an X bitmap file.
547 Load an XPM bitmap file.
553 The validity of these flags depends on the platform and wxWidgets
555 In addition, wxBitmap can read all formats that wxImage can
556 (wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG, wxBITMAP_TYPE_GIF,
557 wxBITMAP_TYPE_PCX, wxBITMAP_TYPE_PNM).
558 (Of course you must have wxImage handlers loaded.)
560 @returns @true if the operation succeeded, @false otherwise.
562 @remarks A palette may be associated with the bitmap if one exists
563 (especially for colour Windows bitmaps), and if the
564 code supports it. You can check if one has been created
565 by using the GetPalette member.
569 bool LoadFile(const wxString
& name
, wxBitmapType type
);
572 Finds the handler with the given name, and removes it. The handler
578 @returns @true if the handler was found and removed, @false otherwise.
582 static bool RemoveHandler(const wxString
& name
);
585 Saves a bitmap in the named file.
588 A filename. The meaning of name is determined by the type parameter.
590 One of the following values:
603 Save a Windows bitmap file.
614 Save a GIF bitmap file.
625 Save an X bitmap file.
636 Save an XPM bitmap file.
642 The validity of these flags depends on the platform and wxWidgets
644 In addition, wxBitmap can save all formats that wxImage can
645 (wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG).
646 (Of course you must have wxImage handlers loaded.)
648 An optional palette used for saving the bitmap.
650 @returns @true if the operation succeeded, @false otherwise.
652 @remarks Depending on how wxWidgets has been configured, not all formats
657 bool SaveFile(const wxString
& name
, wxBitmapType type
,
658 wxPalette
* palette
= NULL
);
661 Sets the depth member (does not affect the bitmap data).
666 void SetDepth(int depth
);
669 Sets the height member (does not affect the bitmap data).
672 Bitmap height in pixels.
674 void SetHeight(int height
);
677 Sets the mask for this bitmap.
679 @remarks The bitmap object owns the mask once this has been called.
681 @see GetMask(), wxMask
683 void SetMask(wxMask
* mask
);
686 Sets the associated palette. (Not implemented under GTK+).
693 void SetPalette(const wxPalette
& palette
);
696 Sets the width member (does not affect the bitmap data).
699 Bitmap width in pixels.
701 void SetWidth(int width
);
704 Assignment operator, using @ref overview_trefcount "reference counting".
709 wxBitmap
operator =(const wxBitmap
& bitmap
);
717 This class encapsulates a monochrome mask bitmap, where the masked area is
719 the unmasked area is white. When associated with a bitmap and drawn in a device
721 the unmasked area of the bitmap will be drawn, and the masked area will not be
728 wxBitmap, wxDC::Blit, wxMemoryDC
730 class wxMask
: public wxObject
735 Constructs a mask from a bitmap and a palette index that indicates the
737 yet implemented for GTK.
742 A colour specifying the transparency RGB values.
744 Index into a palette, specifying the transparency colour.
747 wxMask(const wxBitmap
& bitmap
);
748 wxMask(const wxBitmap
& bitmap
,
749 const wxColour
& colour
);
750 wxMask(const wxBitmap
& bitmap
, int index
);
754 Destroys the wxMask object and the underlying bitmap data.
760 Constructs a mask from a bitmap and a palette index that indicates the
762 yet implemented for GTK.
767 A colour specifying the transparency RGB values.
769 Index into a palette, specifying the transparency colour.
771 bool Create(const wxBitmap
& bitmap
);
772 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
773 bool Create(const wxBitmap
& bitmap
, int index
);