]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/bitmap.h
ff402220129949bede1f0111f786f13e37a8a476
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
95 The bitmap object which is to be affected by this operation.
97 Either a filename or a Windows resource name.
98 The meaning of name is determined by the type parameter.
100 See ::wxBitmapType for values this can take.
102 The desired width for the loaded bitmap.
104 The desired height for the loaded bitmap.
106 @return @true if the operation succeeded, @false otherwise.
108 @see wxBitmap::LoadFile, wxBitmap::SaveFile, SaveFile()
110 virtual bool LoadFile(wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
,
111 int desiredWidth
, int desiredHeight
);
114 Saves a bitmap in the named file.
117 The bitmap object which is to be affected by this operation.
119 A filename. The meaning of name is determined by the type parameter.
121 See ::wxBitmapType for values this can take.
123 An optional palette used for saving the bitmap.
125 @return @true if the operation succeeded, @false otherwise.
127 @see wxBitmap::LoadFile, wxBitmap::SaveFile, LoadFile()
129 virtual bool SaveFile(const wxBitmap
* bitmap
, const wxString
& name
, wxBitmapType type
,
130 const wxPalette
* palette
= NULL
) const;
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(wxBitmapType type
);
161 This class encapsulates the concept of a platform-dependent bitmap,
162 either monochrome or colour or colour with alpha channel support.
164 If you need direct access the bitmap data instead going through
165 drawing to it using wxMemoryDC you need to use the wxPixelData
166 class (either wxNativePixelData for RGB bitmaps or wxAlphaPixelData
167 for bitmaps with an additionally alpha channel).
169 Note that many wxBitmap functions take a @e type parameter, which is a
170 value of the ::wxBitmapType enumeration.
171 The validity of those values depends however on the platform where your program
172 is running and from the wxWidgets configuration.
173 If all possible wxWidgets settings are used:
174 - wxMSW supports BMP and ICO files, BMP and ICO resources;
175 - wxGTK supports XPM files;
176 - wxMac supports PICT resources;
177 - wxX11 supports XPM files, XPM data, XBM data;
179 In addition, wxBitmap can load and save all formats that wxImage can; see wxImage
180 for more info. Of course, you must have loaded the wxImage handlers
181 (see ::wxInitAllImageHandlers() and wxImage::AddHandler).
182 Note that all available wxBitmapHandlers for a given wxWidgets port are
183 automatically loaded at startup so you won't need to use wxBitmap::AddHandler.
185 More on the difference between wxImage and wxBitmap: wxImage is just a
186 buffer of RGB bytes with an optional buffer for the alpha bytes. It is all
187 generic, platform independent and image file format independent code. It
188 includes generic code for scaling, resizing, clipping, and other manipulations
189 of the image data. OTOH, wxBitmap is intended to be a wrapper of whatever is
190 the native image format that is quickest/easiest to draw to a DC or to be the
191 target of the drawing operations performed on a wxMemoryDC. By splitting the
192 responsibilities between wxImage/wxBitmap like this then it's easier to use
193 generic code shared by all platforms and image types for generic operations and
194 platform specific code where performance or compatibility is needed.
202 @see @ref overview_bitmap, @ref overview_bitmap_supportedformats,
203 wxDC::Blit, wxIcon, wxCursor, wxMemoryDC, wxImage, wxPixelData
205 class wxBitmap
: public wxGDIObject
211 Constructs a bitmap object with no data; an assignment or another member
212 function such as Create() or LoadFile() must be called subsequently.
217 Copy constructor, uses @ref overview_refcount "reference counting".
218 To make a real copy, you can use:
221 wxBitmap newBitmap = oldBitmap.GetSubBitmap(
222 wxRect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));
225 wxBitmap(const wxBitmap
& bitmap
);
229 Creates a bitmap from the given @a data which is interpreted in
230 platform-dependent manner.
233 Specifies the bitmap data in a platform-dependent format.
235 May be one of the ::wxBitmapType values and indicates which type of
236 bitmap does @a data contains. See the note in the class
237 detailed description.
239 Specifies the width of the bitmap.
241 Specifies the height of the bitmap.
243 Specifies the depth of the bitmap.
244 If this is omitted, the display depth of the screen is used.
245 wxBitmap(const void* data, int type, int width, int height, int depth = -1);
248 NOTE: this ctor is not implemented by all ports, is somewhat useless
249 without further description of the "data" supported formats and
250 uses 'int type' instead of wxBitmapType, so don't document it.
254 Creates a bitmap from the given array @a bits.
255 You should only use this function for monochrome bitmaps (depth 1) in
256 portable programs: in this case the bits parameter should contain an XBM image.
258 For other bit depths, the behaviour is platform dependent: under Windows,
259 the data is passed without any changes to the underlying CreateBitmap() API.
260 Under other platforms, only monochrome bitmaps may be created using this
261 constructor and wxImage should be used for creating colour bitmaps from
265 Specifies an array of pixel values.
267 Specifies the width of the bitmap.
269 Specifies the height of the bitmap.
271 Specifies the depth of the bitmap.
272 If this is omitted, then a value of 1 (monochrome bitmap) is used.
275 In wxPerl use Wx::Bitmap->newFromBits(bits, width, height, depth).
278 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
281 Creates a new bitmap. A depth of ::wxBITMAP_SCREEN_DEPTH indicates the
282 depth of the current screen or visual.
284 Some platforms only support 1 for monochrome and ::wxBITMAP_SCREEN_DEPTH for
285 the current colour setting.
287 A depth of 32 including an alpha channel is supported under MSW, Mac and GTK+.
289 wxBitmap(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
294 wxBitmap(const wxSize
& sz
, int depth
= wxBITMAP_SCREEN_DEPTH
);
297 Creates a bitmap from XPM data.
300 In wxPerl use Wx::Bitmap->newFromXPM(data).
303 wxBitmap(const char* const* bits
);
306 Loads a bitmap from a file or resource.
309 This can refer to a resource name or a filename under MS Windows and X.
310 Its meaning is determined by the @a type parameter.
312 May be one of the ::wxBitmapType values and indicates which type of
313 bitmap should be loaded. See the note in the class detailed description.
314 Note that the wxBITMAP_DEFAULT_TYPE constant has different value under
315 different wxWidgets ports. See the bitmap.h header for the value it takes
320 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
323 Creates this bitmap object from the given image.
324 This has to be done to actually display an image as you cannot draw an
325 image directly on a window.
327 The resulting bitmap will use the provided colour depth (or that of the
328 current system if depth is ::wxBITMAP_SCREEN_DEPTH) which entails that a
329 colour reduction may take place.
331 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube
332 created on program start-up to look up colors. This ensures a very fast conversion,
333 but the image quality won't be perfect (and could be better for photo images using
334 more sophisticated dithering algorithms).
336 On Windows, if there is a palette present (set with SetPalette), it will be
337 used when creating the wxBitmap (most useful in 8-bit display mode).
338 On other platforms, the palette is currently ignored.
341 Platform-independent wxImage object.
343 Specifies the depth of the bitmap.
344 If this is omitted, the display depth of the screen is used.
346 wxBitmap(const wxImage
& img
, int depth
= wxBITMAP_SCREEN_DEPTH
);
350 See @ref overview_refcount_destruct for more info.
352 If the application omits to delete the bitmap explicitly, the bitmap will be
353 destroyed automatically by wxWidgets when the application exits.
356 Do not delete a bitmap that is selected into a memory device context.
361 Adds a handler to the end of the static list of format handlers.
364 A new bitmap format handler object. There is usually only one instance
365 of a given handler class in an application session.
367 Note that unlike wxImage::AddHandler, there's no documented list of
368 the wxBitmapHandlers available in wxWidgets.
369 This is because they are platform-specific and most important, they are
370 all automatically loaded at startup.
372 If you want to be sure that wxBitmap can load a certain type of image,
373 you'd better use wxImage::AddHandler.
377 static void AddHandler(wxBitmapHandler
* handler
);
380 Deletes all bitmap handlers.
381 This function is called by wxWidgets on exit.
383 static void CleanUpHandlers();
386 Creates an image from a platform-dependent bitmap. This preserves
387 mask information so that bitmaps and images can be converted back
388 and forth without loss in that respect.
390 virtual wxImage
ConvertToImage() const;
393 Creates the bitmap from an icon.
395 virtual bool CopyFromIcon(const wxIcon
& icon
);
398 Creates a fresh bitmap.
399 If the final argument is omitted, the display depth of the screen is used.
401 @return @true if the creation was successful.
403 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
408 virtual bool Create(const wxSize
& sz
, int depth
= wxBITMAP_SCREEN_DEPTH
);
411 Creates a bitmap from the given data, which can be of arbitrary type.
414 Data whose type depends on the value of type.
416 A bitmap type identifier; see ::wxBitmapType for the list of values.
417 See the note in the class detailed description for more info.
419 The width of the bitmap in pixels.
421 The height of the bitmap in pixels.
423 The depth of the bitmap in pixels. If this is -1, the screen depth is used.
425 @return @true if the call succeeded, @false otherwise.
427 This overload depends on the @a type of data.
429 virtual bool Create(const void* data, int type, int width,
430 int height, int depth = -1);
432 NOTE: leave this undoc for the same reason of the relative ctor.
436 Finds the handler with the given @a name.
438 @return A pointer to the handler if found, @NULL otherwise.
440 static wxBitmapHandler
* FindHandler(const wxString
& name
);
443 Finds the handler associated with the given @a extension and @a type.
446 The file extension, such as "bmp" (without the dot).
448 The bitmap type managed by the handler, see ::wxBitmapType.
450 @return A pointer to the handler if found, @NULL otherwise.
452 static wxBitmapHandler
* FindHandler(const wxString
& extension
,
453 wxBitmapType bitmapType
);
456 Finds the handler associated with the given bitmap type.
459 The bitmap type managed by the handler, see ::wxBitmapType.
461 @return A pointer to the handler if found, @NULL otherwise.
466 static wxBitmapHandler
* FindHandler(wxBitmapType bitmapType
);
469 Gets the colour depth of the bitmap.
470 A value of 1 indicates a monochrome bitmap.
472 virtual int GetDepth() const;
475 Returns the static list of bitmap format handlers.
479 static wxList
& GetHandlers();
482 Gets the height of the bitmap in pixels.
484 @see GetWidth(), GetSize()
486 virtual int GetHeight() const;
489 Gets the associated mask (if any) which may have been loaded from a file
490 or set for the bitmap.
492 @see SetMask(), wxMask
494 virtual wxMask
* GetMask() const;
497 Gets the associated palette (if any) which may have been loaded from a file
498 or set for the bitmap.
502 virtual wxPalette
* GetPalette() const;
505 Returns a sub bitmap of the current one as long as the rect belongs entirely to
506 the bitmap. This function preserves bit depth and mask information.
508 virtual wxBitmap
GetSubBitmap(const wxRect
& rect
) const;
511 Returns the size of the bitmap in pixels.
515 @see GetHeight(), GetWidth()
517 wxSize
GetSize() const;
520 Returns disabled (dimmed) version of the bitmap.
522 This method is not available when <code>wxUSE_IMAGE == 0</code>.
526 wxBitmap
ConvertToDisabled(unsigned char brightness
= 255) const;
529 Gets the width of the bitmap in pixels.
531 @see GetHeight(), GetSize()
533 virtual int GetWidth() const;
536 Adds the standard bitmap format handlers, which, depending on wxWidgets
537 configuration, can be handlers for Windows bitmap, Windows bitmap resource,
540 This function is called by wxWidgets on startup.
544 static void InitStandardHandlers();
547 Adds a handler at the start of the static list of format handlers.
550 A new bitmap format handler object. There is usually only one instance
551 of a given handler class in an application session.
555 static void InsertHandler(wxBitmapHandler
* handler
);
558 Returns @true if bitmap data is present.
560 virtual bool IsOk() const;
563 Loads a bitmap from a file or resource.
566 Either a filename or a Windows resource name.
567 The meaning of name is determined by the @a type parameter.
569 One of the ::wxBitmapType values; see the note in the class
570 detailed description.
571 Note that the wxBITMAP_DEFAULT_TYPE constant has different value under
572 different wxWidgets ports. See the bitmap.h header for the value it takes
575 @return @true if the operation succeeded, @false otherwise.
577 @remarks A palette may be associated with the bitmap if one exists
578 (especially for colour Windows bitmaps), and if the
579 code supports it. You can check if one has been created
580 by using the GetPalette() member.
584 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_DEFAULT_TYPE
);
587 Loads a bitmap from the memory containing image data in PNG format.
589 This helper function provides the simplest way to create a wxBitmap
590 from PNG image data. On most platforms, it's simply a wrapper around
591 wxImage loading functions and so requires the PNG image handler to be
592 registered by either calling wxInitAllImageHandlers() which also
593 registers all the other image formats or including the necessary
596 #include <wx/imagpng.h>
600 wxImage::AddHandler(new wxPNGHandler);
602 in your application startup code.
604 However under OS X this function uses native image loading and so
605 doesn't require wxWidgets PNG support.
609 static wxBitmap
NewFromPNGData(const void* data
, size_t size
);
612 Finds the handler with the given name, and removes it.
613 The handler is not deleted.
618 @return @true if the handler was found and removed, @false otherwise.
622 static bool RemoveHandler(const wxString
& name
);
625 Saves a bitmap in the named file.
628 A filename. The meaning of name is determined by the type parameter.
630 One of the ::wxBitmapType values; see the note in the class
631 detailed description.
633 An optional palette used for saving the bitmap.
635 @return @true if the operation succeeded, @false otherwise.
637 @remarks Depending on how wxWidgets has been configured, not all formats
642 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
,
643 const wxPalette
* palette
= NULL
) const;
646 Sets the depth member (does not affect the bitmap data).
648 @todo since these functions do not affect the bitmap data,
654 virtual void SetDepth(int depth
);
657 Sets the height member (does not affect the bitmap data).
660 Bitmap height in pixels.
662 virtual void SetHeight(int height
);
665 Sets the mask for this bitmap.
667 @remarks The bitmap object owns the mask once this has been called.
669 @see GetMask(), wxMask
671 virtual void SetMask(wxMask
* mask
);
674 Sets the associated palette. (Not implemented under GTK+).
681 virtual void SetPalette(const wxPalette
& palette
);
684 Sets the width member (does not affect the bitmap data).
687 Bitmap width in pixels.
689 virtual void SetWidth(int width
);
693 An empty wxBitmap object.
695 wxBitmap wxNullBitmap
;
703 This class encapsulates a monochrome mask bitmap, where the masked area is
704 black and the unmasked area is white.
706 When associated with a bitmap and drawn in a device context, the unmasked
707 area of the bitmap will be drawn, and the masked area will not be drawn.
712 @see wxBitmap, wxDC::Blit, wxMemoryDC
714 class wxMask
: public wxObject
724 Constructs a mask from a bitmap and a palette index that indicates the
726 Not yet implemented for GTK.
731 Index into a palette, specifying the transparency colour.
733 wxMask(const wxBitmap
& bitmap
, int index
);
736 Constructs a mask from a monochrome bitmap.
738 wxMask(const wxBitmap
& bitmap
);
741 Constructs a mask from a bitmap and a colour that indicates the background.
743 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
746 Destroys the wxMask object and the underlying bitmap data.
751 Constructs a mask from a bitmap and a palette index that indicates the
753 Not yet implemented for GTK.
758 Index into a palette, specifying the transparency colour.
760 bool Create(const wxBitmap
& bitmap
, int index
);
763 Constructs a mask from a monochrome bitmap.
765 bool Create(const wxBitmap
& bitmap
);
768 Constructs a mask from a bitmap and a colour that indicates the background.
770 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
773 Returns the mask as a monochrome bitmap.
774 Currently this method is implemented in wxMSW, wxGTK and wxOSX.
778 wxBitmap
GetBitmap() const;