pygame.Surface
pygame object for representing images
Surface((width, height), flags=0, depth=0, masks=None) -> Surface
Surface((width, height), flags=0, Surface) -> Surface
draw one image onto another
draw many images onto another
change the pixel format of an image
change the pixel format of an image including per pixel alphas
create a new copy of a Surface
fill Surface with a solid color
Shift the surface image in place
Set the transparent colorkey
Get the current transparent colorkey
set the alpha value for the full Surface image
get the current Surface transparency value
lock the Surface memory for pixel access
unlock the Surface memory from pixel access
test if the Surface requires locking
test if the Surface is current locked
Gets the locks for the Surface
get the color value at a single pixel
set the color value for a single pixel
get the mapped color value at a single pixel
get the color index palette for an 8-bit Surface
get the color for a single entry in a palette
set the color palette for an 8-bit Surface
set the color for a single index in an 8-bit Surface palette
convert a color into a mapped color value
convert a mapped integer color value into a Color
set the current clipping area of the Surface
get the current clipping area of the Surface
create a new surface that references its parent
find the parent of a subsurface
find the top level parent of a subsurface
find the position of a child subsurface inside a parent
find the absolute position of a child subsurface inside its top level parent
get the dimensions of the Surface
get the width of the Surface
get the height of the Surface
get the rectangular area of the Surface
get the bit depth of the Surface pixel format
get the bytes used per Surface pixel
get the additional flags used for the Surface
get the number of bytes used per Surface row
the bitmasks needed to convert between a color and a mapped integer
set the bitmasks needed to convert between a color and a mapped integer
the bit shifts needed to convert between a color and a mapped integer
sets the bit shifts needed to convert between a color and a mapped integer
the significant bits used to convert between a color and a mapped integer
find the smallest rect containing data
return a buffer view of the Surface's pixels.
acquires a buffer object for the pixels of the Surface.
pixel buffer address

一个PYGAME表面被用来表示任何图像。Surface具有固定的分辨率和像素格式。具有8位像素的曲面使用调色板映射到24位颜色。

打电话 pygame.Surface()pygame object for representing images 若要创建新图像对象,请执行以下操作。表面将被清除为全黑。唯一需要的参数是大小。在没有其他参数的情况下,将以与显示曲面最匹配的格式创建曲面。

可以通过传递位深度或现有的Surface来控制像素格式。FLAGS参数是曲面附加功能的位掩码。您可以传递这些标志的任意组合:

HWSURFACE    (obsolete in pygame 2) creates the image in video memory
SRCALPHA     the pixel format will include a per-pixel alpha

这两个标志只是一个请求,并不是所有的显示和格式都是可能的。

高级用户可以将一组位掩码与深度值组合在一起。掩码是一组4个整数,表示像素中的哪些位将代表每种颜色。法线曲面不应需要遮罩参数。

曲面可以有许多额外的属性,如Alpha平面、色键、源矩形裁剪。这些函数主要影响将曲面传送到其他曲面的方式。Blit例程将在可能的情况下尝试使用硬件加速,否则将使用高度优化的软件blit方法。

在pyGame中支持三种类型的透明度:Colorkey、Surface Alpha和Pixel Alpha。表面Alpha可以与颜色键混合,但具有每像素Alpha的图像不能使用其他模式。Colorkey透明度使单个颜色值透明。不会绘制与Colorkey匹配的任何像素。曲面Alpha值是更改整个图像透明度的单个值。曲面Alpha为255是不透明的,值为0是完全透明的。

每个像素的Alpha是不同的,因为它们存储每个像素的透明值。这可以实现最精确的透明度效果,但也是最慢的。每个像素的Alpha不能与曲面Alpha和颜色键混合。

支持对曲面进行像素访问。硬件表面上的像素访问速度很慢,不推荐使用。像素可以使用 get_at()set_at() 功能。这些方法对于简单的访问是很好的,但当使用它们进行像素工作时会相当慢。如果您计划执行大量的像素级工作,建议使用 pygame.PixelArraypygame object for direct pixel access of surfaces ,它提供了一个类似阵列的曲面视图。对于复杂的数学运算,请尝试 pygame.surfarraypygame module for accessing surface pixel data using array interfaces 模块(它相当快,但需要NumPy。)

任何直接访问表面像素数据的函数都需要锁定该表面()。 lock()unlock() 表面本身在没有帮助的情况下。但是,如果一个函数将被多次调用,则曲面的多重锁定和解锁将会有大量开销。最好在多次调用函数之前手动锁定曲面,然后在完成后解锁。所有需要锁定表面的函数都会在其文档中说明这一点。请记住,仅在必要时才锁定曲面。

曲面像素在内部存储为单个数字,其中包含所有编码的颜色。使用 map_rgb()unmap_rgb() 在单个红色、绿色和蓝色值之间转换为该曲面的压缩整数。

曲面也可以参照其他曲面的截面。这些都是使用 subsurface() 方法。对其中一个曲面的任何更改都会影响另一个曲面。

每个曲面都包含一个剪贴区。默认情况下,剪辑区域覆盖整个曲面。如果更改,所有绘制操作只会影响较小的区域。

blit()
draw one image onto another
blit(source, dest, area=None, special_flags=0) -> Rect

将源曲面绘制到该曲面上。抽签可以用DEST参数来定位。DEST参数可以是表示Blit左上角位置的一对坐标,也可以是一个RECT,其中矩形的左上角将用作Blit的位置。目标矩形的大小不会影响blit。

也可以传递一个可选的面积矩形。这表示要绘制的源曲面的较小部分。

New in pygame 1.8: 可选 special_flagsBLEND_ADDBLEND_SUBBLEND_MULTBLEND_MINBLEND_MAX

New in pygame 1.8.1: 可选 special_flagsBLEND_RGBA_ADDBLEND_RGBA_SUBBLEND_RGBA_MULTBLEND_RGBA_MINBLEND_RGBA_MAX BLEND_RGB_ADDBLEND_RGB_SUBBLEND_RGB_MULTBLEND_RGB_MINBLEND_RGB_MAX

New in pygame 1.9.2: 可选 special_flagsBLEND_PREMULTIPLIED

New in pygame 2.0.0: 可选 special_flagsBLEND_ALPHA_SDL2 -使用SDL2阻击器进行Alpha混合,由于Alpha混合公式使用的近似不同,这与默认阻击器不同,默认阻击器是根据SDL1建模的。SDL2阻击器还支持Alpha混合曲面上的RLE,而pyGame One不支持。

返回矩形是受影响像素的区域,不包括目标曲面或剪切区域之外的任何像素。

像素Alpha将在向8位表面进行blit时被忽略。

对于具有Colorkey或毯子Alpha的曲面,BLIT to Self可能会提供与非Self-Bit略有不同的颜色。

blits()
draw many images onto another
blits(blit_sequence=((source, dest), ...), doreturn=1) -> [Rect, ...] or None
blits(((source, dest, area), ...)) -> [Rect, ...]
blits(((source, dest, area, special_flags), ...)) -> [Rect, ...]

在此曲面上绘制多个曲面。它接受一个序列作为输入,每个元素对应于 blit() 。它至少需要一个(源、目标)序列。

参数
  • blit_sequence -- 一系列曲面和参数对其进行blit,它们对应于 blit() 论据

  • doreturn -- 如果 True ,则返回已更改区域的矩形列表,否则返回 None

返回

在以下情况下更改的区域的矩形列表 doreturnTrue ,否则 None

返回类型

list or None

PYGAME 1.9.4新增功能。

convert()
change the pixel format of an image
convert(Surface=None) -> Surface
convert(depth, flags=0) -> Surface
convert(masks, flags=0) -> Surface

创建更改了像素格式的曲面的新副本。新的像素格式可以从另一个现有的Surface确定。否则,可以使用深度、标志和掩码参数,类似于 pygame.Surface()pygame object for representing images 打电话。

如果没有传递任何参数,则新的Surface将具有与Display Surface相同的像素格式。这始终是最快的数据传输格式。最好先转换所有曲面,然后再对其进行多次BLIT。

转换后的曲面将没有像素Alpha。如果原件有它们,它们将被剥离。看见 convert_alpha() 用于保留或创建每个像素的Alpha。

新副本将与复制的曲面具有相同的类。这使AS Surface子类无需覆盖即可继承此方法,除非子类的特定实例属性也需要复制。

convert_alpha()
change the pixel format of an image including per pixel alphas
convert_alpha(Surface) -> Surface
convert_alpha() -> Surface

创建具有所需像素格式的曲面的新副本。新曲面的格式将适合于使用每像素Alpha快速blit到给定格式。如果未给出曲面,则新曲面将优化为快速显示到当前显示。

不像 convert() 方法时,新图像的像素格式将不会与请求的源的像素格式完全相同,但它将针对快速向目标发送Alpha进行了优化。

和以前一样 convert() 返回的曲面与转换后的曲面具有相同的类。

copy()
create a new copy of a Surface
copy() -> Surface

复制曲面。新曲面将具有与原始曲面相同的像素格式、调色板、透明度设置和类别。如果曲面子类还需要复制任何特定于实例的属性,则它应该重写 copy()

fill()
fill Surface with a solid color
fill(color, rect=None, special_flags=0) -> Rect

使用纯色填充曲面。如果没有给定RECT参数,则整个曲面将被填充。RECT参数将填充限制到特定区域。填充也将包含在曲面剪裁区域中。

颜色参数可以是 RGB 序列,a RGBA 序列或映射的颜色索引。如果使用 RGBA ,The Alpha(的一部分 RGBA )被忽略,除非曲面使用每像素Alpha(Surface具有 SRCALPHA 旗帜)。

New in pygame 1.8: 可选 special_flagsBLEND_ADDBLEND_SUBBLEND_MULTBLEND_MINBLEND_MAX

New in pygame 1.8.1: 可选 special_flagsBLEND_RGBA_ADDBLEND_RGBA_SUBBLEND_RGBA_MULTBLEND_RGBA_MINBLEND_RGBA_MAX BLEND_RGB_ADDBLEND_RGB_SUBBLEND_RGB_MULTBLEND_RGB_MINBLEND_RGB_MAX

这将返回受影响的表面积。

scroll()
Shift the surface image in place
scroll(dx=0, dy=0) -> None

将图像向右移动dx像素,向下移动dy像素。对于左滚动和上滚动,dx和dy可以分别为负值。未被覆盖的曲面区域将保留其原始像素值。滚动包含在曲面剪贴区中。Dx和dy的值超过曲面大小是安全的。

New in pygame 1.9.

set_colorkey()
Set the transparent colorkey
set_colorkey(Color, flags=0) -> None
set_colorkey(None) -> None

设置曲面的当前颜色键。将该曲面传送到目标时,与Colorkey具有相同颜色的任何像素都将是透明的。颜色可以是 RGB 颜色或映射的颜色整数。如果 None 传递后,将取消设置Colorkey。

如果曲面的格式设置为使用每像素Alpha值,则将忽略ColorKey。Colorkey可以与完整的Surface Alpha值混合。

可选标志参数可以设置为 pygame.RLEACCEL 以在非加速显示上提供更好的性能。一个 RLEACCEL 修改表面的速度会更慢,但将其作为源进行blit的速度会更快。

get_colorkey()
Get the current transparent colorkey
get_colorkey() -> RGB or None

返回曲面的当前颜色键值。如果未设置ColorKey,则 None 返回。

set_alpha()
set the alpha value for the full Surface image
set_alpha(value, flags=0) -> None
set_alpha(None) -> None

设置曲面的当前Alpha值。将该曲面绘制到目标上时,像素将被绘制为略微透明。Alpha值是从0到255的整数,0表示完全透明,255表示完全不透明。如果 None 为Alpha值传递,则将禁用Alpha混合,包括每像素Alpha。

该值不同于每像素曲面的Alpha。对于具有每像素Alpha的曲面,覆盖Alpha将被忽略,并且 None 返回。

Changed in pygame 2.0: 每表面Alpha可以与每像素Alpha结合使用。

可选标志参数可以设置为 pygame.RLEACCEL 以在非加速显示上提供更好的性能。一个 RLEACCEL 修改表面的速度会更慢,但将其作为源进行blit的速度会更快。

get_alpha()
get the current Surface transparency value
get_alpha() -> int_value

返回曲面的当前Alpha值。

lock()
lock the Surface memory for pixel access
lock() -> None

锁定曲面的像素数据以供访问。在加速表面上,像素数据可以以易失性视频存储器或非线性压缩形式存储。当一个曲面被锁定时,像素内存就可以通过常规软件访问。读取或写入像素值的代码需要锁定Surface。

如果没有必要,曲面不应保持锁定状态。一个被锁定的表面通常不能被电子游戏显示或管理。

并非所有曲面都需要锁定。这个 mustlock() 方法可以确定它是否确实是必需的。锁定和解锁不需要的曲面不会影响性能。

所有的pyGame功能都会根据需要自动锁定和解锁Surface数据。如果一段代码要进行多次重复锁定和解锁Surface的调用,则将块包装在锁定和解锁对中会很有帮助。

嵌套锁定和解锁调用是安全的。只有在最终锁定解除后,才会解锁曲面。

unlock()
unlock the Surface memory from pixel access
unlock() -> None

锁定曲面像素数据后,将其解锁。解锁的表面可以再次被绘制和管理的PYGAME。请参阅 lock() 文档以了解更多详细信息。

所有的pyGame功能都会根据需要自动锁定和解锁Surface数据。如果一段代码要进行多次重复锁定和解锁Surface的调用,则将块包装在锁定和解锁对中会很有帮助。

嵌套锁定和解锁调用是安全的。只有在最终锁定解除后,才会解锁曲面。

mustlock()
test if the Surface requires locking
mustlock() -> bool

退货 True 如果需要锁定曲面才能访问像素数据。通常,纯软件表面不需要锁定。很少需要此方法,因为仅根据需要锁定所有曲面是安全且最快的。

所有的pyGame功能都会根据需要自动锁定和解锁Surface数据。如果一段代码要进行多次重复锁定和解锁Surface的调用,则将块包装在锁定和解锁对中会很有帮助。

get_locked()
test if the Surface is current locked
get_locked() -> bool

退货 True 当曲面被锁定时。曲面被锁定多少次并不重要。

get_locks()
Gets the locks for the Surface
get_locks() -> tuple

返回曲面的当前现有锁定。

get_at()
get the color value at a single pixel
get_at((x, y)) -> Color

返回一份 RGBA 给定像素处的颜色值。如果曲面没有每像素Alpha,则Alpha值始终为255(不透明)。如果像素位置在曲面区域之外,则 IndexError 将引发异常。

一次获取和设置一个像素通常太慢,不能在游戏或实时情况下使用。最好使用一次对多个像素进行操作的方法,如使用Blit、Fill和Drawing方法,或者使用 pygame.surfarraypygame module for accessing surface pixel data using array interfaces/pygame.PixelArraypygame object for direct pixel access of surfaces

此功能将根据需要临时锁定和解锁曲面。

New in pygame 1.9: 返回颜色而不是元组。使用 tuple(surf.get_at((x,y))) 如果您想要元组,而不是颜色。只有当您想要将颜色用作词典中的关键字时,这才重要。

set_at()
set the color value for a single pixel
set_at((x, y), Color) -> None

设置 RGBA 或映射的单个像素的整数颜色值。如果曲面没有每像素Alpha,则会忽略Alpha值。将像素设置在曲面区域或曲面剪裁之外将不起作用。

一次获取和设置一个像素通常太慢,不能在游戏或实时情况下使用。

此功能将根据需要临时锁定和解锁曲面。

get_at_mapped()
get the mapped color value at a single pixel
get_at_mapped((x, y)) -> Color

返回给定像素的整数值。如果像素位置在曲面区域之外,则 IndexError 将引发异常。

此方法用于进行假游戏单元测试。它不太可能在应用程序中有任何用处。

此功能将根据需要临时锁定和解锁曲面。

New in pygame 1.9.2.

get_palette()
get the color index palette for an 8-bit Surface
get_palette() -> [RGB, RGB, RGB, ...]

返回最多包含256个颜色元素的列表,这些颜色元素表示在8位Surface中使用的索引颜色。返回的列表是调色板的副本,更改不会对曲面产生任何影响。

返回一个列表 Color(with length 3) 实例而不是元组。

New in pygame 1.9.

get_palette_at()
get the color for a single entry in a palette
get_palette_at(index) -> RGB

返回曲面调色板中单个索引的红色、绿色和蓝色颜色值。索引应为介于0和255之间的值。

New in pygame 1.9: 返乡 Color(with length 3) 实例而不是元组。

set_palette()
set the color palette for an 8-bit Surface
set_palette([RGB, RGB, RGB, ...]) -> None

设置8位曲面的完整调色板。这将替换现有调色板中的颜色。可以传递部分调色板,并且只会更改原始调色板中的第一种颜色。

此函数对每像素超过8位的Surface没有影响。

set_palette_at()
set the color for a single index in an 8-bit Surface palette
set_palette_at(index, RGB) -> None

为曲面选项板中的单个条目设置选项板值。索引应为介于0和255之间的值。

此函数对每像素超过8位的Surface没有影响。

map_rgb()
convert a color into a mapped color value
map_rgb(Color) -> mapped_int

转换为 RGBA 颜色转换为该曲面的映射整数值。返回的整数包含的位数不会超过Surface的位深度。映射的颜色值并不经常在pyGame中使用,但可以传递给大多数需要Surface和颜色的函数。

有关颜色和像素格式的详细信息,请参见曲面对象文档。

unmap_rgb()
convert a mapped integer color value into a Color
unmap_rgb(mapped_int) -> Color

将映射的整数颜色转换为 RGB 此曲面的颜色组件。映射的颜色值并不经常在pyGame中使用,但可以传递给大多数需要Surface和颜色的函数。

有关颜色和像素格式的详细信息,请参见曲面对象文档。

set_clip()
set the current clipping area of the Surface
set_clip(rect) -> None
set_clip(None) -> None

每个曲面都有一个活动的剪裁区域。这是一个矩形,表示Surface上唯一可以修改的像素。如果 None 为矩形传递时,整个曲面将可用于更改。

剪裁区域始终限于曲面本身的区域。如果剪裁矩形太大,它将被缩小以适应曲面。

get_clip()
get the current clipping area of the Surface
get_clip() -> Rect

返回当前剪贴区的矩形。Surface将始终返回一个永远不会超出图像边界的有效矩形。如果表面上有 None 为裁剪区域设置,则Surface将返回一个包含整个Surface区域的矩形。

subsurface()
create a new surface that references its parent
subsurface(Rect) -> Surface

返回与其新父级共享其像素的新Surface。新的曲面被认为是原始曲面的子项。对任一曲面像素的修改都会相互影响。像剪裁区域和颜色键这样的曲面信息对于每个曲面都是唯一的。

新曲面将继承其父曲面的调色板、色键和Alpha设置。

父对象上可以有任意数量的子曲面和子曲面。如果显示模式不是硬件加速的,也可以将显示表面埋在地下。

看见 get_offset()get_parent() 以了解更多关于地下表面状态的信息。

子曲面将具有与父曲面相同的类。

get_parent()
find the parent of a subsurface
get_parent() -> Surface

返回子曲面的父曲面。如果这不是地下,那么 None 将会被退还。

get_abs_parent()
find the top level parent of a subsurface
get_abs_parent() -> Surface

返回子曲面的父曲面。如果这不是子曲面,则将返回该曲面。

get_offset()
find the position of a child subsurface inside a parent
get_offset() -> (x, y)

获取父子曲面内部的子子曲面的偏移位置。如果曲面不是子曲面,则返回(0,0)。

get_abs_offset()
find the absolute position of a child subsurface inside its top level parent
get_abs_offset() -> (x, y)

获取子子曲面在其顶层父曲面内部的偏移位置。如果曲面不是子曲面,则返回(0,0)。

get_size()
get the dimensions of the Surface
get_size() -> (width, height)

以像素为单位返回Surface的宽度和高度。

get_width()
get the width of the Surface
get_width() -> width

以像素为单位返回Surface的宽度。

get_height()
get the height of the Surface
get_height() -> height

以像素为单位返回Surface的高度。

get_rect()
get the rectangular area of the Surface
get_rect(**kwargs) -> Rect

返回覆盖整个曲面的新矩形。此矩形将始终从(0,0)开始,宽度和高度与图像的大小相同。

您可以将关键字参数值传递给此函数。在返回RECT之前,这些命名值将应用于RECT的属性。一个例子是 mysurf.get_rect(center=(100, 100)) 若要为居中于给定位置的曲面创建矩形,请执行以下操作。

get_bitsize()
get the bit depth of the Surface pixel format
get_bitsize() -> int

返回用于表示每个像素的位数。该值可能不能准确填充每个像素使用的字节数。例如,15位Surface仍然需要完整的2个字节。

get_bytesize()
get the bytes used per Surface pixel
get_bytesize() -> int

返回每个像素使用的字节数。

get_flags()
get the additional flags used for the Surface
get_flags() -> int

返回一组当前曲面要素。每个特征都是标志位掩码中的一位。典型的标志是 RLEACCELSRCALPHA ,以及 SRCCOLORKEY

以下是更完整的旗帜列表。有关完整列表,请参阅 SDL_video.h

SWSURFACE      0x00000000    # Surface is in system memory
HWSURFACE      0x00000001    # (obsolete in pygame 2) Surface is in video memory
ASYNCBLIT      0x00000004    # (obsolete in pygame 2) Use asynchronous blits if possible

看见 pygame.display.set_mode()Initialize a window or screen for display 用于显示图面专用的标志。

内部使用(只读)

HWACCEL        0x00000100    # Blit uses hardware acceleration
SRCCOLORKEY    0x00001000    # Blit uses a source color key
RLEACCELOK     0x00002000    # Private flag
RLEACCEL       0x00004000    # Surface is RLE encoded
SRCALPHA       0x00010000    # Blit uses source alpha blending
PREALLOC       0x01000000    # Surface uses preallocated memory
get_pitch()
get the number of bytes used per Surface row
get_pitch() -> int

返回Surface中分隔各行的字节数。视频内存中的曲面并不总是线性填充的。子曲面的节距也将大于其实际宽度。

正常的pyGame使用不需要此值。

get_masks()
the bitmasks needed to convert between a color and a mapped integer
get_masks() -> (R, G, B, A)

返回用于隔离映射整数中的每种颜色的位掩码。

正常的pyGame使用不需要此值。

set_masks()
set the bitmasks needed to convert between a color and a mapped integer
set_masks((r,g,b,a)) -> None

这对于正常的电子游戏使用不是必需的。

备注

在SDL2中,掩码是只读的,因此,如果调用此方法,将引发AttributeError。

New in pygame 1.8.1.

get_shifts()
the bit shifts needed to convert between a color and a mapped integer
get_shifts() -> (R, G, B, A)

返回需要在每种颜色和映射的整数之间转换的像素移位。

正常的pyGame使用不需要此值。

set_shifts()
sets the bit shifts needed to convert between a color and a mapped integer
set_shifts((r,g,b,a)) -> None

这对于正常的电子游戏使用不是必需的。

备注

在SDL2中,移位是只读的,因此,如果调用此方法,将引发AttributeError。

New in pygame 1.8.1.

get_losses()
the significant bits used to convert between a color and a mapped integer
get_losses() -> (R, G, B, A)

返回映射整数中从每种颜色中剥离的最低有效位数。

正常的pyGame使用不需要此值。

get_bounding_rect()
find the smallest rect containing data
get_bounding_rect(min_alpha = 1) -> Rect

返回包含表面中Alpha值大于或等于最小Alpha值的所有像素的最小矩形区域。

此功能将根据需要临时锁定和解锁曲面。

New in pygame 1.8.

get_view()
return a buffer view of the Surface's pixels.
get_view(<kind>='2') -> BufferProxy

返回一个对象,该对象将表面的内部像素缓冲区导出为C级数组结构、Python级数组接口或C级缓冲区接口。支持新的缓冲区协议。

Kind参数是长度为1的字符串‘0’、‘1’、‘2’、‘3’、‘r’、‘g’、‘b’或‘a’。这些字母不区分大小写;‘A’也可以。参数可以是Unicode或字节(Char)字符串。默认值为“2”。

“0”返回连续的非结构化字节视图。没有给出曲面形状信息。一个 ValueError 如果曲面的像素不连续,则引发。

‘1’返回连续像素的(Surface-Width*Surface-Height)数组。一个 ValueError 如果曲面像素不连续,则引发。

‘2’返回原始像素的(表面宽度、表面高度)数组。像素是表面字节大小为d的无符号整数。像素格式是特定于曲面的。24位表面的3字节无符号整数不太可能被除假游戏函数以外的任何其他函数接受。

‘3’返回(Surface-Width,Surface-Height,3)数组 RGB 颜色分量。红色、绿色和蓝色分量中的每一个都是无符号字节。仅支持24位和32位曲面。颜色分量必须位于 RGBBGR 像素内的顺序。

‘r’表示红色,‘g’表示绿色,‘b’表示蓝色,‘a’表示Alpha,返回曲面内单个颜色组件的(曲面宽度、曲面高度)视图:颜色平面。颜色分量是无符号字节。24位和32位表面都支持‘r’、‘g’和‘b’。只有32位曲面具有 SRCALPHA 支持‘a’。

仅当访问暴露的界面时,才会锁定曲面。对于新的缓冲区接口访问,一旦释放最后一个缓冲区视图,曲面就会被解锁。对于数组接口和旧的缓冲区接口访问,表面将保持锁定状态,直到释放BufferProxy对象。

New in pygame 1.9.2.

get_buffer()
acquires a buffer object for the pixels of the Surface.
get_buffer() -> BufferProxy

为Surface的像素返回一个缓冲区对象。该缓冲器可用于直接像素访问和操作。表面像素数据表示为非结构化的内存块,具有以字节为单位的起始地址和长度。数据不必是连续的。所有间隙都包含在长度中,但在其他情况下会被忽略。

此方法隐式锁定Surface。返回时,将释放锁 pygame.BufferProxypygame object to export a surface buffer through an array protocol 对象被垃圾回收。

New in pygame 1.8.

_pixels_address
pixel buffer address
_pixels_address -> int

曲面的原始像素字节的起始地址。

New in pygame 1.9.2.




Edit on GitHub