]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxBitmap* classes
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
10 In wxBitmap and wxBitmapHandler context this value means: "use the screen depth".
12 #define wxBITMAP_SCREEN_DEPTH (-1)
15 @class wxBitmapHandler
17 This is the base class for implementing bitmap file loading/saving, and
18 bitmap creation from data.
19 It is used within wxBitmap and is not normally seen by the application.
21 If you wish to extend the capabilities of wxBitmap, derive a class from
22 wxBitmapHandler and add the handler using wxBitmap::AddHandler() in your
23 application initialization.
25 Note that all wxBitmapHandlers provided by wxWidgets are part of the
26 @ref page_libs_wxcore library.
27 For details about the default handlers, please see the note in the
28 wxBitmap class documentation.
33 @see @ref overview_bitmap, wxBitmap, wxIcon, wxCursor
35 class wxBitmapHandler
: public wxObject
41 In your own default constructor, initialise the members m_name,
42 m_extension and m_type.
47 Destroys the wxBitmapHandler object.
49 virtual ~wxBitmapHandler();
52 Creates a bitmap from the given data, which can be of arbitrary type.
53 The wxBitmap object @a bitmap is manipulated by this function.
58 The width of the bitmap in pixels.
60 The height of the bitmap in pixels.
62 The depth of the bitmap in pixels.
63 If this is ::wxBITMAP_SCREEN_DEPTH, the screen depth is used.
65 Data whose type depends on the value of type.
67 A bitmap type identifier - see ::wxBitmapType for a list
70 @return @true if the call succeeded, @false otherwise (the default).
72 virtual bool Create(wxBitmap
* bitmap
, const void* data
, wxBitmapType type
,
73 int width
, int height
, int depth
= 1);
76 Gets the file extension associated with this handler.
78 const wxString
& GetExtension() const;
81 Gets the name of this handler.
83 const wxString
& GetName() const;
86 Gets the bitmap type associated with this handler.
88 wxBitmapType
GetType() const;
91 Loads a bitmap from a file or resource, putting the resulting data into
94 @note Under MSW, when loading a bitmap from resources (i.e. using @c
95 wxBITMAP_TYPE_BMP_RESOURCE as @a type), the light grey colour is
96 considered to be transparent, for historical reasons. If you want
97 to handle the light grey pixels normally instead, call
98 SetMask(NULL) after loading the bitmap.
101 The bitmap object which is to be affected by this operation.
103 Either a filename or a Windows resource name.
104 The meaning of name is determined by the type parameter.
106 See ::wxBitmapType for values this can take.
108 The desired width for the loaded bitmap.
110 The desired height for the loaded bitmap.
112 @return @true if the operation succeeded, @false otherwise.
114 @see wxBitmap::LoadFile, wxBitmap::SaveFile, SaveFile()
116 virtual bool LoadFile(wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
,
117 int desiredWidth
, int desiredHeight
);
120 Saves a bitmap in the named file.
123 The bitmap object which is to be affected by this operation.
125 A filename. The meaning of name is determined by the type parameter.
127 See ::wxBitmapType for values this can take.
129 An optional palette used for saving the bitmap.
131 @return @true if the operation succeeded, @false otherwise.
133 @see wxBitmap::LoadFile, wxBitmap::SaveFile, LoadFile()
135 virtual bool SaveFile(const wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
,
136 const wxPalette
* palette
= NULL
) const;
139 Sets the handler extension.
144 void SetExtension(const wxString
& extension
);
147 Sets the handler name.
152 void SetName(const wxString
& name
);
155 Sets the handler type.
160 void SetType(wxBitmapType type
);
167 This class encapsulates the concept of a platform-dependent bitmap,
168 either monochrome or colour or colour with alpha channel support.
170 If you need direct access the bitmap data instead going through
171 drawing to it using wxMemoryDC you need to use the wxPixelData
172 class (either wxNativePixelData for RGB bitmaps or wxAlphaPixelData
173 for bitmaps with an additionally alpha channel).
175 Note that many wxBitmap functions take a @e type parameter, which is a
176 value of the ::wxBitmapType enumeration.
177 The validity of those values depends however on the platform where your program
178 is running and from the wxWidgets configuration.
179 If all possible wxWidgets settings are used:
180 - wxMSW supports BMP and ICO files, BMP and ICO resources;
181 - wxGTK supports XPM files;
182 - wxMac supports PICT resources;
183 - wxX11 supports XPM files, XPM data, XBM data;
185 In addition, wxBitmap can load and save all formats that wxImage can; see wxImage
186 for more info. Of course, you must have loaded the wxImage handlers
187 (see ::wxInitAllImageHandlers() and wxImage::AddHandler).
188 Note that all available wxBitmapHandlers for a given wxWidgets port are
189 automatically loaded at startup so you won't need to use wxBitmap::AddHandler.
191 More on the difference between wxImage and wxBitmap: wxImage is just a
192 buffer of RGB bytes with an optional buffer for the alpha bytes. It is all
193 generic, platform independent and image file format independent code. It
194 includes generic code for scaling, resizing, clipping, and other manipulations
195 of the image data. OTOH, wxBitmap is intended to be a wrapper of whatever is
196 the native image format that is quickest/easiest to draw to a DC or to be the
197 target of the drawing operations performed on a wxMemoryDC. By splitting the
198 responsibilities between wxImage/wxBitmap like this then it's easier to use
199 generic code shared by all platforms and image types for generic operations and
200 platform specific code where performance or compatibility is needed.
208 @see @ref overview_bitmap, @ref overview_bitmap_supportedformats,
209 wxDC::Blit, wxIcon, wxCursor, wxMemoryDC, wxImage, wxPixelData
211 class wxBitmap
: public wxGDIObject
217 Constructs a bitmap object with no data; an assignment or another member
218 function such as Create() or LoadFile() must be called subsequently.
223 Copy constructor, uses @ref overview_refcount "reference counting".
224 To make a real copy, you can use:
227 wxBitmap newBitmap = oldBitmap.GetSubBitmap(
228 wxRect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));
231 wxBitmap(const wxBitmap
& bitmap
);
235 Creates a bitmap from the given @a data which is interpreted in
236 platform-dependent manner.
239 Specifies the bitmap data in a platform-dependent format.
241 May be one of the ::wxBitmapType values and indicates which type of
242 bitmap does @a data contains. See the note in the class
243 detailed description.
245 Specifies the width of the bitmap.
247 Specifies the height of the bitmap.
249 Specifies the depth of the bitmap.
250 If this is omitted, the display depth of the screen is used.
251 wxBitmap(const void* data, int type, int width, int height, int depth = -1);
254 NOTE: this ctor is not implemented by all ports, is somewhat useless
255 without further description of the "data" supported formats and
256 uses 'int type' instead of wxBitmapType, so don't document it.
260 Creates a bitmap from the given array @a bits.
261 You should only use this function for monochrome bitmaps (depth 1) in
262 portable programs: in this case the bits parameter should contain an XBM image.
264 For other bit depths, the behaviour is platform dependent: under Windows,
265 the data is passed without any changes to the underlying CreateBitmap() API.
266 Under other platforms, only monochrome bitmaps may be created using this
267 constructor and wxImage should be used for creating colour bitmaps from
271 Specifies an array of pixel values.
273 Specifies the width of the bitmap.
275 Specifies the height of the bitmap.
277 Specifies the depth of the bitmap.
278 If this is omitted, then a value of 1 (monochrome bitmap) is used.
281 In wxPerl use Wx::Bitmap->newFromBits(bits, width, height, depth).
284 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
287 Creates a new bitmap. A depth of ::wxBITMAP_SCREEN_DEPTH indicates the
288 depth of the current screen or visual.
290 Some platforms only support 1 for monochrome and ::wxBITMAP_SCREEN_DEPTH for
291 the current colour setting.
293 A depth of 32 including an alpha channel is supported under MSW, Mac and GTK+.
295 wxBitmap(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
300 wxBitmap(const wxSize
& sz
, int depth
= wxBITMAP_SCREEN_DEPTH
);
303 Creates a bitmap from XPM data.
306 In wxPerl use Wx::Bitmap->newFromXPM(data).
309 wxBitmap(const char* const* bits
);
312 Loads a bitmap from a file or resource.
315 This can refer to a resource name or a filename under MS Windows and X.
316 Its meaning is determined by the @a type parameter.
318 May be one of the ::wxBitmapType values and indicates which type of
319 bitmap should be loaded. See the note in the class detailed description.
320 Note that the wxBITMAP_DEFAULT_TYPE constant has different value under
321 different wxWidgets ports. See the bitmap.h header for the value it takes
326 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
329 Creates this bitmap object from the given image.
330 This has to be done to actually display an image as you cannot draw an
331 image directly on a window.
333 The resulting bitmap will use the provided colour depth (or that of the
334 current system if depth is ::wxBITMAP_SCREEN_DEPTH) which entails that a
335 colour reduction may take place.
337 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
338 created on program start-up to look up colors. This ensures a very fast conversion,
339 but the image quality won't be perfect (and could be better for photo images using
340 more sophisticated dithering algorithms).
342 On Windows, if there is a palette present (set with SetPalette), it will be
343 used when creating the wxBitmap (most useful in 8-bit display mode).
344 On other platforms, the palette is currently ignored.
347 Platform-independent wxImage object.
349 Specifies the depth of the bitmap.
350 If this is omitted, the display depth of the screen is used.
352 wxBitmap(const wxImage
& img
, int depth
= wxBITMAP_SCREEN_DEPTH
);
356 See @ref overview_refcount_destruct for more info.
358 If the application omits to delete the bitmap explicitly, the bitmap will be
359 destroyed automatically by wxWidgets when the application exits.
362 Do not delete a bitmap that is selected into a memory device context.
367 Adds a handler to the end of the static list of format handlers.
370 A new bitmap format handler object. There is usually only one instance
371 of a given handler class in an application session.
373 Note that unlike wxImage::AddHandler, there's no documented list of
374 the wxBitmapHandlers available in wxWidgets.
375 This is because they are platform-specific and most important, they are
376 all automatically loaded at startup.
378 If you want to be sure that wxBitmap can load a certain type of image,
379 you'd better use wxImage::AddHandler.
383 static void AddHandler(wxBitmapHandler
* handler
);
386 Deletes all bitmap handlers.
387 This function is called by wxWidgets on exit.
389 static void CleanUpHandlers();
392 Creates an image from a platform-dependent bitmap. This preserves
393 mask information so that bitmaps and images can be converted back
394 and forth without loss in that respect.
396 virtual wxImage
ConvertToImage() const;
399 Creates the bitmap from an icon.
401 virtual bool CopyFromIcon(const wxIcon
& icon
);
404 Creates a fresh bitmap.
405 If the final argument is omitted, the display depth of the screen is used.
407 @return @true if the creation was successful.
409 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
414 virtual bool Create(const wxSize
& sz
, int depth
= wxBITMAP_SCREEN_DEPTH
);
417 Creates a bitmap from the given data, which can be of arbitrary type.
420 Data whose type depends on the value of type.
422 A bitmap type identifier; see ::wxBitmapType for the list of values.
423 See the note in the class detailed description for more info.
425 The width of the bitmap in pixels.
427 The height of the bitmap in pixels.
429 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
431 @return @true if the call succeeded, @false otherwise.
433 This overload depends on the @a type of data.
435 virtual bool Create(const void* data, int type, int width,
436 int height, int depth = -1);
438 NOTE: leave this undoc for the same reason of the relative ctor.
442 Finds the handler with the given @a name.
444 @return A pointer to the handler if found, @NULL otherwise.
446 static wxBitmapHandler
* FindHandler(const wxString
& name
);
449 Finds the handler associated with the given @a extension and @a type.
452 The file extension, such as "bmp" (without the dot).
454 The bitmap type managed by the handler, see ::wxBitmapType.
456 @return A pointer to the handler if found, @NULL otherwise.
458 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
459 wxBitmapType bitmapType
);
462 Finds the handler associated with the given bitmap type.
465 The bitmap type managed by the handler, see ::wxBitmapType.
467 @return A pointer to the handler if found, @NULL otherwise.
472 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
475 Gets the colour depth of the bitmap.
476 A value of 1 indicates a monochrome bitmap.
478 virtual int GetDepth() const;
481 Returns the static list of bitmap format handlers.
485 static wxList
& GetHandlers();
488 Gets the height of the bitmap in pixels.
490 @see GetWidth(), GetSize()
492 virtual int GetHeight() const;
495 Gets the associated mask (if any) which may have been loaded from a file
496 or set for the bitmap.
498 @see SetMask(), wxMask
500 virtual wxMask
* GetMask() const;
503 Gets the associated palette (if any) which may have been loaded from a file
504 or set for the bitmap.
508 virtual wxPalette
* GetPalette() const;
511 Returns a sub bitmap of the current one as long as the rect belongs entirely to
512 the bitmap. This function preserves bit depth and mask information.
514 virtual wxBitmap
GetSubBitmap(const wxRect
& rect
) const;
517 Returns the size of the bitmap in pixels.
521 @see GetHeight(), GetWidth()
523 wxSize
GetSize() const;
526 Returns disabled (dimmed) version of the bitmap.
528 This method is not available when <code>wxUSE_IMAGE == 0</code>.
532 wxBitmap
ConvertToDisabled(unsigned char brightness
= 255) const;
535 Gets the width of the bitmap in pixels.
537 @see GetHeight(), GetSize()
539 virtual int GetWidth() const;
542 Adds the standard bitmap format handlers, which, depending on wxWidgets
543 configuration, can be handlers for Windows bitmap, Windows bitmap resource,
546 This function is called by wxWidgets on startup.
550 static void InitStandardHandlers();
553 Adds a handler at the start of the static list of format handlers.
556 A new bitmap format handler object. There is usually only one instance
557 of a given handler class in an application session.
561 static void InsertHandler(wxBitmapHandler
* handler
);
564 Returns @true if bitmap data is present.
566 virtual bool IsOk() const;
569 Loads a bitmap from a file or resource.
572 Either a filename or a Windows resource name.
573 The meaning of name is determined by the @a type parameter.
575 One of the ::wxBitmapType values; see the note in the class
576 detailed description.
577 Note that the wxBITMAP_DEFAULT_TYPE constant has different value under
578 different wxWidgets ports. See the bitmap.h header for the value it takes
581 @return @true if the operation succeeded, @false otherwise.
583 @remarks A palette may be associated with the bitmap if one exists
584 (especially for colour Windows bitmaps), and if the
585 code supports it. You can check if one has been created
586 by using the GetPalette() member.
590 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
593 Loads a bitmap from the memory containing image data in PNG format.
595 This helper function provides the simplest way to create a wxBitmap
596 from PNG image data. On most platforms, it's simply a wrapper around
597 wxImage loading functions and so requires the PNG image handler to be
598 registered by either calling wxInitAllImageHandlers() which also
599 registers all the other image formats or including the necessary
602 #include <wx/imagpng.h>
606 wxImage::AddHandler(new wxPNGHandler);
608 in your application startup code.
610 However under OS X this function uses native image loading and so
611 doesn't require wxWidgets PNG support.
615 static wxBitmap
NewFromPNGData(const void* data
, size_t size
);
618 Finds the handler with the given name, and removes it.
619 The handler is not deleted.
624 @return @true if the handler was found and removed, @false otherwise.
628 static bool RemoveHandler(const wxString
& name
);
631 Saves a bitmap in the named file.
634 A filename. The meaning of name is determined by the type parameter.
636 One of the ::wxBitmapType values; see the note in the class
637 detailed description.
639 An optional palette used for saving the bitmap.
641 @return @true if the operation succeeded, @false otherwise.
643 @remarks Depending on how wxWidgets has been configured, not all formats
648 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
,
649 const wxPalette
* palette
= NULL
) const;
652 Sets the depth member (does not affect the bitmap data).
654 @todo since these functions do not affect the bitmap data,
660 virtual void SetDepth(int depth
);
663 Sets the height member (does not affect the bitmap data).
666 Bitmap height in pixels.
668 virtual void SetHeight(int height
);
671 Sets the mask for this bitmap.
673 @remarks The bitmap object owns the mask once this has been called.
675 @see GetMask(), wxMask
677 virtual void SetMask(wxMask
* mask
);
680 Sets the associated palette. (Not implemented under GTK+).
687 virtual void SetPalette(const wxPalette
& palette
);
690 Sets the width member (does not affect the bitmap data).
693 Bitmap width in pixels.
695 virtual void SetWidth(int width
);
699 An empty wxBitmap object.
701 wxBitmap wxNullBitmap
;
709 This class encapsulates a monochrome mask bitmap, where the masked area is
710 black and the unmasked area is white.
712 When associated with a bitmap and drawn in a device context, the unmasked
713 area of the bitmap will be drawn, and the masked area will not be drawn.
718 @see wxBitmap, wxDC::Blit, wxMemoryDC
720 class wxMask
: public wxObject
730 Constructs a mask from a bitmap and a palette index that indicates the
732 Not yet implemented for GTK.
737 Index into a palette, specifying the transparency colour.
739 wxMask(const wxBitmap
& bitmap
, int index
);
742 Constructs a mask from a monochrome bitmap.
744 wxMask(const wxBitmap
& bitmap
);
747 Constructs a mask from a bitmap and a colour that indicates the background.
749 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
752 Destroys the wxMask object and the underlying bitmap data.
757 Constructs a mask from a bitmap and a palette index that indicates the
759 Not yet implemented for GTK.
764 Index into a palette, specifying the transparency colour.
766 bool Create(const wxBitmap
& bitmap
, int index
);
769 Constructs a mask from a monochrome bitmap.
771 bool Create(const wxBitmap
& bitmap
);
774 Constructs a mask from a bitmap and a colour that indicates the background.
776 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
779 Returns the mask as a monochrome bitmap.
780 Currently this method is implemented in wxMSW, wxGTK and wxOSX.
784 wxBitmap
GetBitmap() const;