bitmap.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: bitmap.h
  3. // Purpose: topic overview
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @page overview_bitmap Bitmaps and Icons
  9. @tableofcontents
  10. The wxBitmap class encapsulates the concept of a platform-dependent bitmap,
  11. either monochrome or colour. Platform-specific methods for creating a wxBitmap
  12. object from an existing file are catered for, and this is an occasion where
  13. conditional compilation will sometimes be required.
  14. A bitmap created dynamically or loaded from a file can be selected into a
  15. memory device context (instance of wxMemoryDC). This enables the bitmap to be
  16. copied to a window or memory device context using wxDC::Blit(), or to be used
  17. as a drawing surface.
  18. See wxMemoryDC for an example of drawing onto a bitmap.
  19. All wxWidgets platforms support XPMs for small bitmaps and icons. You may
  20. include the XPM inline as below, since it's C code, or you can load it at
  21. run-time.
  22. @code
  23. #include "sample.xpm"
  24. @endcode
  25. Sometimes you wish to use a .ico resource on Windows, and XPMs on other
  26. platforms (for example to take advantage of Windows' support for multiple icon
  27. resolutions).
  28. A macro, wxICON(), is available which creates an icon using an XPM on the
  29. appropriate platform, or an icon resource on Windows:
  30. @code
  31. wxIcon icon(wxICON(sample));
  32. // The above line is equivalent to this:
  33. #if defined(__WXGTK__) || defined(__WXMOTIF__)
  34. wxIcon icon(sample_xpm);
  35. #endif
  36. #if defined(__WXMSW__)
  37. wxIcon icon("sample");
  38. #endif
  39. @endcode
  40. There is also a corresponding wxBITMAP() macro which allows to create the
  41. bitmaps in much the same way as wxICON() creates icons. It assumes that bitmaps
  42. live in resources under Windows or OS2 and XPM files under all other platforms
  43. (for XPMs, the corresponding file must be included before this macro is used,
  44. of course, and the name of the bitmap should be the same as the resource name
  45. under Windows with @c _xpm suffix). For example:
  46. @code
  47. // an easy and portable way to create a bitmap
  48. wxBitmap bmp(wxBITMAP(bmpname));
  49. // which is roughly equivalent to the following
  50. #if defined(__WXMSW__) || defined(__WXPM__)
  51. wxBitmap bmp("bmpname", wxBITMAP_TYPE_BMP_RESOURCE);
  52. #else // Unix
  53. wxBitmap bmp(bmpname_xpm, wxBITMAP_TYPE_XPM);
  54. #endif
  55. @endcode
  56. You should always use wxICON() and wxBITMAP() macros because they work for any
  57. platform (unlike the code above which doesn't deal with wxMac, wxX11, ...) and
  58. are shorter and more clear than versions with many @ifdef_ blocks.
  59. Alternatively, you could use the same XPMs on all platforms and avoid dealing
  60. with Windows resource files.
  61. If you'd like to embed bitmaps with alpha transparency in your program, neither
  62. XPM nor BMP formats are appropriate as they don't have support for alpha and
  63. another format, typically PNG, should be used. wxWidgets provides a similar
  64. helper for PNG bitmaps called wxBITMAP_PNG() that can be used to either load
  65. PNG files embedded in resources (meaning either Windows resource section of the
  66. executable file or OS X "Resource" subdirectory of the application bundle) or
  67. arrays containing PNG data included into the program code itself.
  68. @see @ref group_class_gdi
  69. @section overview_bitmap_supportedformats Supported Bitmap File Formats
  70. The following lists the formats handled on different platforms. Note that
  71. missing or partially-implemented formats are automatically supplemented by
  72. using wxImage to load the data, and then converting it to wxBitmap form. Note
  73. that using wxImage is the preferred way to load images in wxWidgets, with the
  74. exception of resources (XPM-files or native Windows resources).
  75. Writing an image format handler for wxImage is also far easier than writing one
  76. for wxBitmap, because wxImage has exactly one format on all platforms whereas
  77. wxBitmap can store pixel data very differently, depending on colour depths and
  78. platform.
  79. @subsection overview_bitmap_supportedformats_bmp wxBitmap
  80. Under Windows, wxBitmap may load the following formats:
  81. @li Windows bitmap resource (wxBITMAP_TYPE_BMP_RESOURCE)
  82. @li Windows bitmap file (wxBITMAP_TYPE_BMP)
  83. @li XPM data and file (wxBITMAP_TYPE_XPM)
  84. @li All formats that are supported by the wxImage class.
  85. Under wxGTK, wxBitmap may load the following formats:
  86. @li XPM data and file (wxBITMAP_TYPE_XPM)
  87. @li All formats that are supported by the wxImage class.
  88. Under wxMotif and wxX11, wxBitmap may load the following formats:
  89. @li XBM data and file (wxBITMAP_TYPE_XBM)
  90. @li XPM data and file (wxBITMAP_TYPE_XPM)
  91. @li All formats that are supported by the wxImage class.
  92. @subsection overview_bitmap_supportedformats_icon wxIcon
  93. Under Windows, wxIcon may load the following formats:
  94. @li Windows icon resource (wxBITMAP_TYPE_ICO_RESOURCE)
  95. @li Windows icon file (wxBITMAP_TYPE_ICO)
  96. @li XPM data and file (wxBITMAP_TYPE_XPM)
  97. Under wxGTK, wxIcon may load the following formats:
  98. @li XPM data and file (wxBITMAP_TYPE_XPM)
  99. @li All formats that are supported by the wxImage class.
  100. Under wxMotif and wxX11, wxIcon may load the following formats:
  101. @li XBM data and file (wxBITMAP_TYPE_XBM)
  102. @li XPM data and file (wxBITMAP_TYPE_XPM)
  103. @li All formats that are supported by the wxImage class.
  104. @subsection overview_bitmap_supportedformats_cursor wxCursor
  105. Under Windows, wxCursor may load the following formats:
  106. @li Windows cursor resource (wxBITMAP_TYPE_CUR_RESOURCE)
  107. @li Windows cursor file (wxBITMAP_TYPE_CUR)
  108. @li Windows icon file (wxBITMAP_TYPE_ICO)
  109. @li Windows bitmap file (wxBITMAP_TYPE_BMP)
  110. Under wxGTK, wxCursor may load the following formats (in addition to stock
  111. cursors):
  112. @li None (stock cursors only).
  113. Under wxMotif and wxX11, wxCursor may load the following formats:
  114. @li XBM data and file (wxBITMAP_TYPE_XBM)
  115. @section overview_bitmap_handlers Bitmap Format Handlers
  116. To provide extensibility, the functionality for loading and saving bitmap
  117. formats is not implemented in the wxBitmap class, but in a number of handler
  118. classes, derived from wxBitmapHandler. There is a static list of handlers which
  119. wxBitmap examines when a file load/save operation is requested.
  120. Some handlers are provided as standard, but if you have special requirements,
  121. you may wish to initialise the wxBitmap class with some extra handlers which
  122. you write yourself or receive from a third party.
  123. To add a handler object to wxBitmap, your application needs to include the
  124. header which implements it, and then call the static function
  125. wxBitmap::AddHandler().
  126. @note Bitmap handlers are not implemented on all platforms, and new ones rarely
  127. need to be implemented since wxImage can be used for loading most formats, as
  128. noted earlier.
  129. */