1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
|
.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2018 by Total Control Software
License: wxWindows License
.. include:: headings.inc
.. _wx.Bitmap:
==========================================================================================================================================
|phoenix_title| **wx.Bitmap**
==========================================================================================================================================
This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or colour with alpha channel support.
If you need direct access the bitmap data instead going through drawing to it using :ref:`wx.MemoryDC` you need to use the :ref:`PixelData` class (either NativePixelData for ``RGB`` bitmaps or AlphaPixelData for bitmaps with an additionally alpha channel).
Note that many :ref:`wx.Bitmap` functions take a `type` parameter, which is a value of the :ref:`wx.BitmapType` enumeration. The validity of those values depends however on the platform where your program is running and from the wxWidgets configuration. If all possible wxWidgets settings are used:
- wxMSW supports ``BMP`` and ``ICO`` files, ``BMP`` and ``ICO`` resources;
- wxGTK supports any file supported by gdk-pixbuf;
- Mac supports ``PICT`` resources;
- X11 supports XPM files, XPM data, ``XBM`` data;
In addition, :ref:`wx.Bitmap` can load and save all formats that :ref:`wx.Image` can; see :ref:`wx.Image` for more info. Of course, you must have loaded the :ref:`wx.Image` handlers (see :ref:`wx.InitAllImageHandlers` and :meth:`wx.Image.AddHandler` ). Note that all available BitmapHandlers for a given wxWidgets port are automatically loaded at startup so you won't need to use :meth:`wx.Bitmap.AddHandler` .
More on the difference between :ref:`wx.Image` and :ref:`wx.Bitmap`: :ref:`wx.Image` is just a buffer of ``RGB`` bytes with an optional buffer for the alpha bytes. It is all generic, platform independent and image file format independent code. It includes generic code for scaling, resizing, clipping, and other manipulations of the image data. OTOH, :ref:`wx.Bitmap` is intended to be a wrapper of whatever is the native image format that is quickest/easiest to draw to a DC or to be the target of the drawing operations performed on a :ref:`wx.MemoryDC`. By splitting the responsibilities between Image/wxBitmap like this then it's easier to use generic code shared by all platforms and image types for generic operations and platform specific code where performance or compatibility is needed.
.. seealso:: :ref:`Bitmaps and Icons <bitmaps and icons>`, :ref:`Supported Bitmap File Formats <supported bitmap file formats>`, :meth:`wx.DC.Blit` , :ref:`wx.Icon`, :ref:`wx.Cursor`, :ref:`wx.MemoryDC`, :ref:`wx.Image`, :ref:`PixelData`
|
|class_hierarchy| Class Hierarchy
=================================
.. raw:: html
<div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
<img id="toggleBlock-trigger" src="_static/images/closed.png"/>
Inheritance diagram for class <strong>Bitmap</strong>:
</div>
<div id="toggleBlock-summary" style="display:block;"></div>
<div id="toggleBlock-content" style="display:none;">
<p class="graphviz">
<center><img src="_static/images/inheritance/wx.Bitmap_inheritance.png" alt="Inheritance diagram of Bitmap" usemap="#dummy" class="inheritance"/></center>
</div>
<script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
<map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.Object.html" title="wx.Object" alt="" coords="17,5,99,35"/> <area shape="rect" id="node3" href="wx.GDIObject.html" title="wx.GDIObject" alt="" coords="5,83,112,112"/> <area shape="rect" id="node2" href="wx.Bitmap.html" title="wx.Bitmap" alt="" coords="15,160,103,189"/> </map>
</p>
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.Bitmap.__init__` Default constructor.
:meth:`~wx.Bitmap.ConvertToDisabled` Returns disabled (dimmed) version of the bitmap.
:meth:`~wx.Bitmap.ConvertToImage` Creates an image from a platform-dependent bitmap.
:meth:`~wx.Bitmap.CopyFromBuffer` Copy data from a buffer object to replace the bitmap pixel data.
:meth:`~wx.Bitmap.CopyFromIcon` Creates the bitmap from an icon.
:meth:`~wx.Bitmap.CopyToBuffer` Copy pixel data to a buffer object. See :meth:`~Bitmap.CopyFromBuffer` for buffer
:meth:`~wx.Bitmap.Create` Creates a fresh bitmap.
:meth:`~wx.Bitmap.FromBuffer` Creates a :class:`wx.Bitmap` from in-memory data. The data parameter
:meth:`~wx.Bitmap.FromBufferAndAlpha` Creates a :class:`wx.Bitmap` from in-memory data. The data and alpha
:meth:`~wx.Bitmap.FromBufferRGBA` Creates a :class:`wx.Bitmap` from in-memory data. The data parameter
:meth:`~wx.Bitmap.FromRGBA` Creates a new empty 32-bit :class:`wx.Bitmap` where every pixel has been
:meth:`~wx.Bitmap.GetDepth` Gets the colour depth of the bitmap.
:meth:`~wx.Bitmap.GetHandle` MSW-only method to fetch the windows handle for the bitmap.
:meth:`~wx.Bitmap.GetHeight` Gets the height of the bitmap in pixels.
:meth:`~wx.Bitmap.GetMask` Gets the associated mask (if any) which may have been loaded from a file or set for the bitmap.
:meth:`~wx.Bitmap.GetPalette` Gets the associated palette (if any) which may have been loaded from a file or set for the bitmap.
:meth:`~wx.Bitmap.GetSize` Returns the size of the bitmap in pixels.
:meth:`~wx.Bitmap.GetSubBitmap` Returns a sub bitmap of the current one as long as the rect belongs entirely to the bitmap.
:meth:`~wx.Bitmap.GetWidth` Gets the width of the bitmap in pixels.
:meth:`~wx.Bitmap.IsOk` Returns ``True`` if bitmap data is present.
:meth:`~wx.Bitmap.LoadFile` Loads a bitmap from a file or resource.
:meth:`~wx.Bitmap.NewFromPNGData` Loads a bitmap from the memory containing image data in ``PNG`` format.
:meth:`~wx.Bitmap.SaveFile` Saves a bitmap in the named file.
:meth:`~wx.Bitmap.SetDepth` Sets the depth member (does not affect the bitmap data).
:meth:`~wx.Bitmap.SetHandle` MSW-only method to set the windows handle for the bitmap.
:meth:`~wx.Bitmap.SetHeight` Sets the height member (does not affect the bitmap data).
:meth:`~wx.Bitmap.SetMask` Sets the mask for this bitmap.
:meth:`~wx.Bitmap.SetMaskColour`
:meth:`~wx.Bitmap.SetPalette` Sets the associated palette.
:meth:`~wx.Bitmap.SetSize` Set the bitmap size (does not alter the existing native bitmap data or image size).
:meth:`~wx.Bitmap.SetWidth` Sets the width member (does not affect the bitmap data).
:meth:`~wx.Bitmap.__bool__`
:meth:`~wx.Bitmap.__nonzero__`
================================================================================ ================================================================================
|
|property_summary| Properties Summary
=====================================
================================================================================ ================================================================================
:attr:`~wx.Bitmap.Depth` See :meth:`~wx.Bitmap.GetDepth` and :meth:`~wx.Bitmap.SetDepth`
:attr:`~wx.Bitmap.Handle` See :meth:`~wx.Bitmap.GetHandle` and :meth:`~wx.Bitmap.SetHandle`
:attr:`~wx.Bitmap.Height` See :meth:`~wx.Bitmap.GetHeight` and :meth:`~wx.Bitmap.SetHeight`
:attr:`~wx.Bitmap.Mask` See :meth:`~wx.Bitmap.GetMask` and :meth:`~wx.Bitmap.SetMask`
:attr:`~wx.Bitmap.Palette` See :meth:`~wx.Bitmap.GetPalette` and :meth:`~wx.Bitmap.SetPalette`
:attr:`~wx.Bitmap.Size` See :meth:`~wx.Bitmap.GetSize` and :meth:`~wx.Bitmap.SetSize`
:attr:`~wx.Bitmap.Width` See :meth:`~wx.Bitmap.GetWidth` and :meth:`~wx.Bitmap.SetWidth`
================================================================================ ================================================================================
|
|api| Class API
===============
.. class:: wx.Bitmap(GDIObject)
**Possible constructors**::
Bitmap()
Bitmap(bitmap)
Bitmap(bits, width, height, depth=1)
Bitmap(width, height, depth=BITMAP_SCREEN_DEPTH)
Bitmap(sz, depth=BITMAP_SCREEN_DEPTH)
Bitmap(name, type=BITMAP_TYPE_ANY)
Bitmap(img, depth=BITMAP_SCREEN_DEPTH)
Bitmap(listOfBytes)
This class encapsulates the concept of a platform-dependent bitmap,
either monochrome or colour or colour with alpha channel support.
.. method:: __init__(self, *args, **kw)
|overload| Overloaded Implementations:
**~~~**
**__init__** `(self)`
Default constructor.
Constructs a bitmap object with no data; an assignment or another member function such as :meth:`Create` or :meth:`LoadFile` must be called subsequently.
**~~~**
**__init__** `(self, bitmap)`
Copy constructor, uses :ref:`reference counting <reference counting>`.
To make a real copy, you can use:
::
newBitmap = oldBitmap.GetSubBitmap(
wx.Rect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()))
:param `bitmap`:
:type `bitmap`: wx.Bitmap
**~~~**
**__init__** `(self, bits, width, height, depth=1)`
Creates a bitmap from the given array `bits`.
You should only use this function for monochrome bitmaps (depth 1) in portable programs: in this case the bits parameter should contain an ``XBM`` image.
For other bit depths, the behaviour is platform dependent: under Windows, the data is passed without any changes to the underlying CreateBitmap() API. Under other platforms, only monochrome bitmaps may be created using this constructor and :ref:`wx.Image` should be used for creating colour bitmaps from static data.
:param `bits`: Specifies an array of pixel values.
:type `bits`: string
:param `width`: Specifies the width of the bitmap.
:type `width`: int
:param `height`: Specifies the height of the bitmap.
:type `height`: int
:param `depth`: Specifies the depth of the bitmap. If this is omitted, then a value of 1 (monochrome bitmap) is used.
:type `depth`: int
**~~~**
**__init__** `(self, width, height, depth=BITMAP_SCREEN_DEPTH)`
Creates a new bitmap.
A depth of ``BITMAP_SCREEN_DEPTH`` indicates the depth of the current screen or visual.
Some platforms only support 1 for monochrome and ``BITMAP_SCREEN_DEPTH`` for the current colour setting.
A depth of 32 including an alpha channel is supported under MSW, Mac and GTK+.
:param `width`:
:type `width`: int
:param `height`:
:type `height`: int
:param `depth`:
:type `depth`: int
**~~~**
**__init__** `(self, sz, depth=BITMAP_SCREEN_DEPTH)`
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `sz`:
:type `sz`: wx.Size
:param `depth`:
:type `depth`: int
**~~~**
**__init__** `(self, name, type=BITMAP_TYPE_ANY)`
Loads a bitmap from a file or resource.
:param `name`: This can refer to a resource name or a filename under MS Windows and X. Its meaning is determined by the `type` parameter.
:type `name`: string
:param `type`: May be one of the :ref:`wx.BitmapType` values and indicates which type of bitmap should be loaded. See the note in the class detailed description. Note that the ``BITMAP_DEFAULT_TYPE`` constant has different value under different wxWidgets ports. See the bitmap.h header for the value it takes for a specific port.
:type `type`: wx.BitmapType
.. seealso:: :meth:`LoadFile`
**~~~**
**__init__** `(self, img, depth=BITMAP_SCREEN_DEPTH)`
Creates this bitmap object from the given image.
This has to be done to actually display an image as you cannot draw an image directly on a window.
The resulting bitmap will use the provided colour depth (or that of the current system if depth is ``BITMAP_SCREEN_DEPTH``) which entails that a colour reduction may take place.
On Windows, if there is a palette present (set with SetPalette), it will be used when creating the :ref:`wx.Bitmap` (most useful in 8-bit display mode). On other platforms, the palette is currently ignored.
:param `img`: Platform-independent :ref:`wx.Image` object.
:type `img`: wx.Image
:param `depth`: Specifies the depth of the bitmap. If this is omitted, the display depth of the screen is used.
:type `depth`: int
**~~~**
**__init__** `(self, listOfBytes)`
Construct a Bitmap from a list of strings formatted as XPM data.
**~~~**
.. method:: ConvertToDisabled(self, brightness=255)
Returns disabled (dimmed) version of the bitmap.
This method is not available when ``USE_IMAGE == 0`` .
:param `brightness`:
:type `brightness`: int
:rtype: :ref:`wx.Bitmap`
.. versionadded:: 2.9.0
.. method:: ConvertToImage(self)
Creates an image from a platform-dependent bitmap.
This preserves mask information so that bitmaps and images can be converted back and forth without loss in that respect.
:rtype: :ref:`wx.Image`
.. method:: CopyFromBuffer(self, data, format=BitmapBufferFormat_RGB, stride=-1)
Copy data from a buffer object to replace the bitmap pixel data.
Default format is plain ``RGB``, but other formats are now supported as
well. The following symbols are used to specify the format of the
bytes in the buffer:
============================= ================================
wx.BitmapBufferFormat_RGB A simple sequence of ``RGB`` bytes
wx.BitmapBufferFormat_RGBA A simple sequence of ``RGBA`` bytes
wx.BitmapBufferFormat_ARGB32 A sequence of 32-bit values in native endian order, with alpha in the upper 8 bits, followed by red, green, and blue.
wx.BitmapBufferFormat_RGB32 Same as above but the alpha byte is ignored.
============================= ================================
.. method:: CopyFromIcon(self, icon)
Creates the bitmap from an icon.
:param `icon`:
:type `icon`: wx.Icon
:rtype: `bool`
.. method:: CopyToBuffer(self, data, format=BitmapBufferFormat_RGB, stride=-1)
Copy pixel data to a buffer object. See :meth:`CopyFromBuffer` for buffer
format details.
.. method:: Create(self, *args, **kw)
|overload| Overloaded Implementations:
**~~~**
**Create** `(self, width, height, depth=BITMAP_SCREEN_DEPTH)`
Creates a fresh bitmap.
If the final argument is omitted, the display depth of the screen is used.
:param `width`:
:type `width`: int
:param `height`:
:type `height`: int
:param `depth`:
:type `depth`: int
:rtype: `bool`
:returns:
``True`` if the creation was successful.
**~~~**
**Create** `(self, sz, depth=BITMAP_SCREEN_DEPTH)`
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `sz`:
:type `sz`: wx.Size
:param `depth`:
:type `depth`: int
:rtype: `bool`
**~~~**
.. staticmethod:: FromBuffer(width, height, data)
Creates a :class:`wx.Bitmap` from in-memory data. The data parameter
must be a Python object that implements the buffer interface, such
as a string, bytearray, etc. The data object is expected to contain
a series of ``RGB`` bytes and be at least widthheight3 bytes long.
Unlike :func:`wx.ImageFromBuffer` the bitmap created with this function
does not share the memory block with the buffer object. This is
because the native pixel buffer format varies on different
platforms, and so instead an efficient as possible copy of the
data is made from the buffer object to the bitmap's native pixel
buffer.
:rtype: :ref:`wx.Bitmap`
.. staticmethod:: FromBufferAndAlpha(width, height, data, alpha)
Creates a :class:`wx.Bitmap` from in-memory data. The data and alpha
parameters must be a Python object that implements the buffer
interface, such as a string, bytearray, etc. The data object
is expected to contain a series of ``RGB`` bytes and be at least
widthheight3 bytes long, while the alpha object is expected
to be widthheight bytes long and represents the image's alpha
channel. On Windows and Mac the ``RGB`` values will be
'premultiplied' by the alpha values. (The other platforms do
the multiplication themselves.)
Unlike :func:`wx.ImageFromBuffer` the bitmap created with this function
does not share the memory block with the buffer object. This is
because the native pixel buffer format varies on different
platforms, and so instead an efficient as possible copy of the
data is made from the buffer object to the bitmap's native pixel
buffer.
:rtype: :ref:`wx.Bitmap`
.. staticmethod:: FromBufferRGBA(width, height, data)
Creates a :class:`wx.Bitmap` from in-memory data. The data parameter
must be a Python object that implements the buffer interface, such
as a string, bytearray, etc. The data object is expected to contain
a series of ``RGBA`` bytes and be at least widthheight4 bytes long.
On Windows and Mac the ``RGB`` values will be 'premultiplied' by the
alpha values. (The other platforms do the multiplication themselves.)
Unlike :func:`wx.ImageFromBuffer` the bitmap created with this function
does not share the memory block with the buffer object. This is
because the native pixel buffer format varies on different
platforms, and so instead an efficient as possible copy of the
data is made from the buffer object to the bitmap's native pixel
buffer.
:rtype: :ref:`wx.Bitmap`
.. staticmethod:: FromRGBA(width, height, red=0, green=0, blue=0, alpha=0)
Creates a new empty 32-bit :class:`wx.Bitmap` where every pixel has been
initialized with the given ``RGBA`` values.
:rtype: :ref:`wx.Bitmap`
.. method:: GetDepth(self)
Gets the colour depth of the bitmap.
A value of 1 indicates a monochrome bitmap.
:rtype: `int`
.. method:: GetHandle(self)
MSW-only method to fetch the windows handle for the bitmap.
:rtype: `long`
.. method:: GetHeight(self)
Gets the height of the bitmap in pixels.
:rtype: `int`
.. seealso:: :meth:`GetWidth` , :meth:`GetSize`
.. method:: GetMask(self)
Gets the associated mask (if any) which may have been loaded from a file or set for the bitmap.
:rtype: :ref:`wx.Mask`
.. seealso:: :meth:`SetMask` , :ref:`wx.Mask`
.. method:: GetPalette(self)
Gets the associated palette (if any) which may have been loaded from a file or set for the bitmap.
:rtype: :ref:`wx.Palette`
.. seealso:: :ref:`wx.Palette`
.. method:: GetSize(self)
Returns the size of the bitmap in pixels.
:rtype: :ref:`wx.Size`
.. versionadded:: 2.9.0
.. seealso:: :meth:`GetHeight` , :meth:`GetWidth`
.. method:: GetSubBitmap(self, rect)
Returns a sub bitmap of the current one as long as the rect belongs entirely to the bitmap.
This function preserves bit depth and mask information.
:param `rect`:
:type `rect`: wx.Rect
:rtype: :ref:`wx.Bitmap`
.. method:: GetWidth(self)
Gets the width of the bitmap in pixels.
:rtype: `int`
.. seealso:: :meth:`GetHeight` , :meth:`GetSize`
.. method:: IsOk(self)
Returns ``True`` if bitmap data is present.
:rtype: `bool`
.. method:: LoadFile(self, name, type=BITMAP_TYPE_ANY)
Loads a bitmap from a file or resource.
:param `name`: Either a filename or a Windows resource name. The meaning of name is determined by the `type` parameter.
:type `name`: string
:param `type`: One of the :ref:`wx.BitmapType` values; see the note in the class detailed description. Note that the ``BITMAP_DEFAULT_TYPE`` constant has different value under different wxWidgets ports. See the bitmap.h header for the value it takes for a specific port.
:type `type`: wx.BitmapType
:rtype: `bool`
:returns:
``True`` if the operation succeeded, ``False`` otherwise.
.. note::
A palette may be associated with the bitmap if one exists (especially for colour Windows bitmaps), and if the code supports it. You can check if one has been created by using the :meth:`GetPalette` member.
.. seealso:: :meth:`SaveFile`
.. staticmethod:: NewFromPNGData(data, size)
Loads a bitmap from the memory containing image data in ``PNG`` format.
This helper function provides the simplest way to create a :ref:`wx.Bitmap` from ``PNG`` image data. On most platforms, it's simply a wrapper around :ref:`wx.Image` loading functions and so requires the ``PNG`` image handler to be registered by either calling :ref:`wx.InitAllImageHandlers` which also registers all the other image formats or including the necessary header: ::
and calling ::
wx.Image.AddHandler(wx.PNGHandler)
in your application startup code.
However under OS X this function uses native image loading and so doesn't require wxWidgets ``PNG`` support.
:param `data`:
:param `size`:
:type `size`: int
:rtype: :ref:`wx.Bitmap`
.. versionadded:: 2.9.5
.. method:: SaveFile(self, name, type, palette=None)
Saves a bitmap in the named file.
:param `name`: A filename. The meaning of name is determined by the type parameter.
:type `name`: string
:param `type`: One of the :ref:`wx.BitmapType` values; see the note in the class detailed description.
:type `type`: wx.BitmapType
:param `palette`: An optional palette used for saving the bitmap.
:type `palette`: wx.Palette
:rtype: `bool`
:returns:
``True`` if the operation succeeded, ``False`` otherwise.
.. note::
Depending on how wxWidgets has been configured, not all formats may be available.
.. seealso:: :meth:`LoadFile`
.. method:: SetDepth(self, depth)
Sets the depth member (does not affect the bitmap data).
:param `depth`: Bitmap depth.
:type `depth`: int
.. todo:: since these functions do not affect the bitmap data, why they exist??
.. method:: SetHandle(self, handle)
MSW-only method to set the windows handle for the bitmap.
.. method:: SetHeight(self, height)
Sets the height member (does not affect the bitmap data).
:param `height`: Bitmap height in pixels.
:type `height`: int
.. method:: SetMask(self, mask)
Sets the mask for this bitmap.
:param `mask`:
:type `mask`: wx.Mask
.. note::
The bitmap object owns the mask once this has been called.
.. seealso:: :meth:`GetMask` , :ref:`wx.Mask`
.. method:: SetMaskColour(self, colour)
.. method:: SetPalette(self, palette)
Sets the associated palette.
(Not implemented under GTK+).
:param `palette`: The palette to set.
:type `palette`: wx.Palette
.. seealso:: :ref:`wx.Palette`
.. method:: SetSize(self, size)
Set the bitmap size (does not alter the existing native bitmap data or image size).
.. method:: SetWidth(self, width)
Sets the width member (does not affect the bitmap data).
:param `width`: Bitmap width in pixels.
:type `width`: int
.. method:: __bool__(self)
:rtype: `int`
.. method:: __nonzero__(self)
:rtype: `int`
.. attribute:: Depth
See :meth:`~wx.Bitmap.GetDepth` and :meth:`~wx.Bitmap.SetDepth`
.. attribute:: Handle
See :meth:`~wx.Bitmap.GetHandle` and :meth:`~wx.Bitmap.SetHandle`
.. attribute:: Height
See :meth:`~wx.Bitmap.GetHeight` and :meth:`~wx.Bitmap.SetHeight`
.. attribute:: Mask
See :meth:`~wx.Bitmap.GetMask` and :meth:`~wx.Bitmap.SetMask`
.. attribute:: Palette
See :meth:`~wx.Bitmap.GetPalette` and :meth:`~wx.Bitmap.SetPalette`
.. attribute:: Size
See :meth:`~wx.Bitmap.GetSize` and :meth:`~wx.Bitmap.SetSize`
.. attribute:: Width
See :meth:`~wx.Bitmap.GetWidth` and :meth:`~wx.Bitmap.SetWidth`
|