版本3和4间的区别
于2006-09-29 14:51:45修订的的版本3
大小: 3864
编辑: czk
备注:
于2006-10-08 14:35:42修订的的版本4
大小: 10154
编辑: czk
备注:
删除的内容标记成这样。 加入的内容标记成这样。
行号 1: 行号 1:
[[TableOfContents]]
行号 34: 行号 36:
== Surface.blit ==

      draw one image onto another
      Surface.blit(source, dest, area=None, special_flags = 0): return Rect

      Draws a source Surface onto this Surface. The draw can be positioned with the dest argument. Dest can either be pair of coordinates representing the upper left corner of the source. A Rect can also be passed as the destination and the topleft corner of the rectangle will be used as the position for the blit. The size of the destination rectangle does not effect the blit.

      An optional area rectangle can be passed as well. This represents a smaller portion of the source Surface to draw.

      An optional special flags is for passing in BLEND_ADD, BLEND_SUB, BLEND_MULT, BLEND_MIN, BLEND_MAX With other special blitting flags perhaps added in the future.

      The return rectangle is the area of the affected pixels, excluding any pixels outside the destination Surface, or outside the clipping area.

      Pixel alphas will be ignored when blitting to an 8 bit Surface.

      special_flags new in pygame 1.8.
       

== Surface.convert ==

      change the pixel format of an image
      Surface.convert(Surface): return Surface
      Surface.convert(depth, flags=0): return Surface
      Surface.convert(masks, flags=0): return Surface
      Surface.convert(): return Surface

      Creates a new copy of the Surface with the pixel format changed. The new pixel format can be determined from another existing Surface. Otherwise depth, flags, and masks arguments can be used, similar to the pygame.Surface - pygame object for representing images call.

      If no arguments are passed the new Surface will have the same pixel format as the display Surface. This is always the fastest format for blitting. It is a good idea to convert all Surfaces before they are blitted many times.

      The converted Surface will have no pixel alphas. They will be stripped if the original had them. See Surface.convert_alpha - change the pixel format of an image including per pixel alphas for preserving or creating per-pixel alphas.

== Surface.copy ==

      create a new copy of a Surface
      Surface.copy(): return Surface

      Makes a duplicate copy of a Surface. The new Surface will have the same pixel formats, color palettes, and transparency settings as the original.

== Surface.fill ==

      fill Surface with a solid color
      Surface.fill(color, rect=None): return Rect

      Fill the Surface with a solid color. If no rect argument is given the entire Surface will be filled. The rect argument will limit the fill to a specific area. The fill will also be contained by the Surface clip area.

      The color argument can be either an RGB sequence or a mapped color index.

      This will return the affected Surface area.

== Surface.set_colorkey ==

      Set the transparent colorkey
      Surface.set_colorkey(Color, flags=0): return None
      Surface.set_colorkey(None): return None

      Set the current color key for the Surface. When blitting this Surface onto a destination, and pixels that have the same color as the colorkey will be transparent. The color can be an RGB color or a mapped color integer. If None is passed, the colorkey will be unset.

      The colorkey will be ignored if the Surface is formatted to use per pixel alpha values. The colorkey can be mixed with the full Surface alpha value.

      The optional flags argument can be set to pygame.RLEACCEL to provide better performance on non accelerated displays. An RLEACCEL Surface will be slower to modify, but quicker to blit as a source.


== Surface.get_at ==

      get the color value at a single pixel
      Surface.get_at((x, y)): return Color

      Return the RGBA color value at the given pixel. If the Surface has no per pixel alpha, then the alpha value will always be 255 (opaque). If the pixel position is outside the area of the Surface an IndexError exception will be raised.

      Getting and setting pixels one at a time is generally too slow to be used in a game or realtime situation.

      This function will temporarily lock and unlock the Surface as needed.
       

== Surface.set_at ==

      set the color value for a single pixel
      Surface.set_at((x, y), Color): return None

      Set the RGBA or mapped integer color value for a single pixel. If the Surface does not have per pixel alphas, the alpha value is ignored. Settting pixels outside the Surface area or outside the Surface clipping will have no effect.

      Getting and setting pixels one at a time is generally too slow to be used in a game or realtime situation.

      This function will temporarily lock and unlock the Surface as needed.

== Surface.set_clip ==

      set the current clipping area of the Surface
      Surface.set_clip(rect): return None
      Surface.set_clip(None): return None

      Each Surface has an active clipping area. This is a rectangle that represents the only pixels on the Surface that can be modified. If None is passed for the rectangle the full Surface will be available for changes.

      The clipping area is always restricted to the area of the Surface itself. If the clip rectangle is too large it will be shrunk to fit inside the Surface.
       

== Surface.get_clip ==

      get the current clipping are of the Surface
      Surface.get_clip(): return Rect

      Return a rectangle of the current clipping area. The Surface will always return a valid rectangle that will never be outside the bounds of the image. If the Surface has had None set for the clipping area, the Surface will return a rectangle with the full area of the Surface.


== Surface.get_size ==

      get the dimensions of the Surface
      Surface.get_size(): return (width, height)

      Return the width and height of the Surface in pixels.
       

== Surface.get_width ==

      get the width of the Surface
      Surface.get_width(): return width

      Return the width of the Surface in pixels.
       

== Surface.get_height ==

      get the height of the Surface
      Surface.get_height(): return height

      Return the height of the Surface in pixels.

TableOfContents

Surface

pygame里的Surface是用来表示图像的对象。Surface有一定的大小和像素格式。如果是8bit像素格式的Surface,它还会用一个调色板映射到24比特颜色。

调用pygame.Surface可以创建表示图像的新对象。Surface会整个全是黑的。唯一需要指定的参数是大小。如果不指定其他参数,Surface的像素格式会与display Surface的像素格式尽量一致。

像素格式可以通过指定像素深度或者已有的Surface来控制。flag标志位参数是其他一些Surface选项的集合,你可以指定如下的标志

  • HWSURFACE, 在视频内存中创建图像
  • SRCALPHA, 像素格式中会包含一个alpha通道

这些参数都仅仅是一个请求,在实际中可能并不能实现。

Advance users can combine a set of bitmasks with a depth value. The masks are a set of 4 integers representing which bits in a pixel will represent each color. Normal Surfaces should not require the masks argument.

Surfaces can have many extra attributes like alpha planes, colorkeys, source rectangle clipping. These functions mainly effect how the Surface is blitted to other Surfaces. The blit routines will attempt to use hardware acceleratio

  • when possible, otherwise will use highly optimized software blitting methods.

There are three types of transparency supported in Pygame: colorkeys, surface alphas, and pixel alphas. Surface alphas can be mixed with colorkeys, but an image with per pixel alphas cannot use the other modes. Colorkey transparency makes a single color value transparent. Any pixels matching the colorkey will not be drawn. The surface alpha value is a single value that changes the transparency for the entire image. A surface alpha of 255 is opaque, and a value of 0 is completely transparent.

Per pixel alphas are different because they store a transparency value for every pixel. This allows for the most precise transparency effects, but it also the slowest. Per pixel alphas cannot be mixed with surface alpha and colorkeys.

There is support for pixel access for the Surfaces. Pixel access on hardware surfaces is slow and not recommended. Pixels can be accessed using the get_at() and set_at() functions. These methods are fine for simple access, but will be considerably slow when doing of pixel work with them. If you plan on doing a lot of pixel level work, it is recommended to use the pygame.surfarray module, which can treat the surfaces like large multidimensional arrays (and it's quite quick).

Any functions that directly access a surface's pixel data will need that surface to be lock()'ed. These functions can lock() and unlock() the surfaces themselves without assistance. But, if a function will be called many times, there will be a lot of overhead for multiple locking and unlocking of the surface. It is best to lock the surface manually before making the function call many times, and then unlocking when you are finished. All functions that need a locked surface will say so in their docs. Remember to leave the Surface locked only while necessary.

Surface pixels are stored internally as a single number that has all the colors encoded into it. Use the Surface.map_rgb - convert a color into a mapped color value and Surface.unmap_rgb - convert a mapped integer color value into a Color to convert between individual red, green, and blue values into a packed integer for that Surface.

Surfaces can also reference sections of other Surfaces. These are created with the Surface.subsurface - create a new surface that references its parent method. Any change to either Surface will effect the other.

Each Surface contains a clipping area. By default the clip area covers the entire Surface. If it is changed, all drawing operations will only effect the smaller area.

1. Surface.blit

  • draw one image onto another Surface.blit(source, dest, area=None, special_flags = 0): return Rect Draws a source Surface onto this Surface. The draw can be positioned with the dest argument. Dest can either be pair of coordinates representing the upper left corner of the source. A Rect can also be passed as the destination and the topleft corner of the rectangle will be used as the position for the blit. The size of the destination rectangle does not effect the blit. An optional area rectangle can be passed as well. This represents a smaller portion of the source Surface to draw. An optional special flags is for passing in BLEND_ADD, BLEND_SUB, BLEND_MULT, BLEND_MIN, BLEND_MAX With other special blitting flags perhaps added in the future. The return rectangle is the area of the affected pixels, excluding any pixels outside the destination Surface, or outside the clipping area. Pixel alphas will be ignored when blitting to an 8 bit Surface. special_flags new in pygame 1.8.

2. Surface.convert

  • change the pixel format of an image Surface.convert(Surface): return Surface Surface.convert(depth, flags=0): return Surface Surface.convert(masks, flags=0): return Surface Surface.convert(): return Surface Creates a new copy of the Surface with the pixel format changed. The new pixel format can be determined from another existing Surface. Otherwise depth, flags, and masks arguments can be used, similar to the pygame.Surface - pygame object for representing images call. If no arguments are passed the new Surface will have the same pixel format as the display Surface. This is always the fastest format for blitting. It is a good idea to convert all Surfaces before they are blitted many times. The converted Surface will have no pixel alphas. They will be stripped if the original had them. See Surface.convert_alpha - change the pixel format of an image including per pixel alphas for preserving or creating per-pixel alphas.

3. Surface.copy

  • create a new copy of a Surface Surface.copy(): return Surface Makes a duplicate copy of a Surface. The new Surface will have the same pixel formats, color palettes, and transparency settings as the original.

4. Surface.fill

  • fill Surface with a solid color Surface.fill(color, rect=None): return Rect Fill the Surface with a solid color. If no rect argument is given the entire Surface will be filled. The rect argument will limit the fill to a specific area. The fill will also be contained by the Surface clip area. The color argument can be either an RGB sequence or a mapped color index. This will return the affected Surface area.

5. Surface.set_colorkey

  • Set the transparent colorkey Surface.set_colorkey(Color, flags=0): return None Surface.set_colorkey(None): return None Set the current color key for the Surface. When blitting this Surface onto a destination, and pixels that have the same color as the colorkey will be transparent. The color can be an RGB color or a mapped color integer. If None is passed, the colorkey will be unset. The colorkey will be ignored if the Surface is formatted to use per pixel alpha values. The colorkey can be mixed with the full Surface alpha value. The optional flags argument can be set to pygame.RLEACCEL to provide better performance on non accelerated displays. An RLEACCEL Surface will be slower to modify, but quicker to blit as a source.

6. Surface.get_at

  • get the color value at a single pixel Surface.get_at((x, y)): return Color

    Return the RGBA color value at the given pixel. If the Surface has no per pixel alpha, then the alpha value will always be 255 (opaque). If the pixel position is outside the area of the Surface an IndexError exception will be raised. Getting and setting pixels one at a time is generally too slow to be used in a game or realtime situation. This function will temporarily lock and unlock the Surface as needed.

7. Surface.set_at

  • set the color value for a single pixel Surface.set_at((x, y), Color): return None Set the RGBA or mapped integer color value for a single pixel. If the Surface does not have per pixel alphas, the alpha value is ignored. Settting pixels outside the Surface area or outside the Surface clipping will have no effect. Getting and setting pixels one at a time is generally too slow to be used in a game or realtime situation. This function will temporarily lock and unlock the Surface as needed.

8. Surface.set_clip

  • set the current clipping area of the Surface Surface.set_clip(rect): return None Surface.set_clip(None): return None Each Surface has an active clipping area. This is a rectangle that represents the only pixels on the Surface that can be modified. If None is passed for the rectangle the full Surface will be available for changes. The clipping area is always restricted to the area of the Surface itself. If the clip rectangle is too large it will be shrunk to fit inside the Surface.

9. Surface.get_clip

  • get the current clipping are of the Surface Surface.get_clip(): return Rect Return a rectangle of the current clipping area. The Surface will always return a valid rectangle that will never be outside the bounds of the image. If the Surface has had None set for the clipping area, the Surface will return a rectangle with the full area of the Surface.

10. Surface.get_size

  • get the dimensions of the Surface Surface.get_size(): return (width, height) Return the width and height of the Surface in pixels.

11. Surface.get_width

  • get the width of the Surface Surface.get_width(): return width Return the width of the Surface in pixels.

12. Surface.get_height

  • get the height of the Surface Surface.get_height(): return height Return the height of the Surface in pixels.

image

draw

Pygame图形接口基础 (2008-02-23 15:34:18由localhost编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.